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

validate cfinput using regular expression

Participant ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

Hi,

can somebody help me valditing an cfinput field using regular expressions?

First digit must be a number or "R".

Digit 2-15 can be everything without special characters. Digit 2-15 can also be empty.

I try this, but it doesn't work (Sorry I'm a beginner using regex).

<cfinput type="text" name="field1" required="yes" validate="regular_expression"  pattern="[0-9Rr][0-9a-zA-Z]*"  maxlength="15">

Thank you in advice!

Claudia

Views

3.5K

Translate

Translate

Report

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

Contributor , Oct 15, 2010 Oct 15, 2010

^[0-9Rr]([0-9a-zA-Z]{1,14})?$

Votes

Translate

Translate
LEGEND ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

You haven't told your regex to match the entire string, so it will "pass"

any string that has your match anywhere within it, so like as long as it's

got an R or a digit in it: it's OK.

To tell it to match the entire string, anchor it to the start and end of the

string with ^ and $ respectively.

Regular expression syntax: Using special characters

http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0a38f-7ffb.html#WSc3ff6d0ea77859461172e0811cbec0a38f-7fef

--

Adam

Votes

Translate

Translate

Report

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
Participant ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

Hi Adam,

okay, first digit is clear, but the rest of the string is not clear to me.

How to check if all other digits are empty or have no sprecial characters in it?

can you please give me an example?

Claudai

Votes

Translate

Translate

Report

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
LEGEND ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

Your regex is basically correct. All you need to do is to say "and make

sure it matches the entire string", not just "any substring", like you

currently have.

To do this, one forces the regex to match from the beginning of the string,

right through to the end of the string.

So, for example a regex of "ant" would match "ant" or "pants" or

"elephant". However "^ant$" would not match "pants" or "elephant" because

the "^" means "match the beginning of the string", and "$" means "match the

end of the string". In effect this makes it so your regex must match the

entire string.

Make sense?

--

Adam

Votes

Translate

Translate

Report

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
Participant ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

Sorry, when I get on your nerves but

do you mean this?

[0-9Rr]^0-9a-zA-Z$

Could you please give me the solution?

C.

Votes

Translate

Translate

Report

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
Contributor ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

^[0-9Rr]([0-9a-zA-Z]{1,14})?$

Votes

Translate

Translate

Report

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
Participant ,
Oct 15, 2010 Oct 15, 2010

Copy link to clipboard

Copied

LATEST

Thank you very much!!

It works.

C.

Votes

Translate

Translate

Report

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
Documentation