Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Regex not working

Explorer ,
Feb 02, 2011 Feb 02, 2011

Can anyone tell me why my regex is not working on my cfinput textbox please. I only want to allow a-z as available charactors to enter and the below code fails.

<cfinput type="text"
        id="surname"
        name="surname"
        class="txt"
        title="Surname"
        value="#presentsurname#"
        validate="regex"
        pattern="[a-z]"
        message="Please enter a valid Surname."
        maxlength="60" />

If i type in $$$ then the regex is flagged up and I get the error message displayed.

Although if I type in a$$, I get no error message.


Thanks,

G

782
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Feb 02, 2011 Feb 02, 2011

Try putting the start and end chars in, ie ^ at the start and $ at the end to make sure it's matching the entire string.

Translate
Participant ,
Feb 02, 2011 Feb 02, 2011

The regex you are using is only checking the first character in the string - and only checking to make sure its lowercase.

Try using *

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 02, 2011 Feb 02, 2011

That would only allow one character, try [a-z]+ to allow one or more.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 02, 2011 Feb 02, 2011

Thanks for the quick replies guys, your really helpful and both regex examples you have given both work.

To cut a long story short I was give the following regex to use against my surname textbox, and I need to follow 'their' standards so I must use this pattern.

([A-Z'\-]*)|([A-Z'\-][A-Z '\-]*[A-Z'\-])

And this should only allow A-Z (in capitals) and any of the other special charactors that are mentioned in the regex....  Although this pattern is allowing me to enter A$$ and I do not understand why it is allowing the $ sign to be an enterable charactor when the dollar sign is not listed in the regex.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Feb 02, 2011 Feb 02, 2011

Try putting the start and end chars in, ie ^ at the start and $ at the end to make sure it's matching the entire string.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 02, 2011 Feb 02, 2011
LATEST

Looks like you found a fix,

There is a tool I use called RegexBuddy that helps me debug Regular Expressions in real time. Also has a gui to help you build a Regular expressions, thats how I started but now I can write them with no problems.

http://www.regexbuddy.com/

rexbuddy.PNG

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources