Skip to main content
Known Participant
April 13, 2010
Answered

Need help validating a form field server side

  • April 13, 2010
  • 5 replies
  • 796 views

Sorry for the entry level question but how can I validate a text field server side

to check if it contains at least one capital letter, one number and one character?

Thanks

This topic has been closed for replies.
Correct answer BKBK

andy99 wrote:

Sorry for the entry level question but how can I validate a text field server side

to check if it contains at least one capital letter, one number and one character?

...

I meant special characters like @#$%^&*

<!--- The pound sign(#) is a special Coldfusion symbol, and is
escaped with #. The dollar($), caret(^) and asterisk(*) are
special regex characters, and so are escaped with a backslash(\). --->


<cfset specialChars="[@##\$%\^&\*]">

<cfset testString="asdf@123.com">

<cfif REFind("[A-Z]",testString) GT 0 and REFind("[0-9]",testString) GT 0 and REFind(specialChars,testString) GT 0>
There's a match.
<cfelse>
There's no match.
</cfif>

5 replies

Known Participant
April 15, 2010

Thank you BKBK.

Cheers

BKBK
Community Expert
Community Expert
April 15, 2010

No thanks.

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
April 15, 2010

andy99 wrote:

Sorry for the entry level question but how can I validate a text field server side

to check if it contains at least one capital letter, one number and one character?

...

I meant special characters like @#$%^&*

<!--- The pound sign(#) is a special Coldfusion symbol, and is
escaped with #. The dollar($), caret(^) and asterisk(*) are
special regex characters, and so are escaped with a backslash(\). --->


<cfset specialChars="[@##\$%\^&\*]">

<cfset testString="asdf@123.com">

<cfif REFind("[A-Z]",testString) GT 0 and REFind("[0-9]",testString) GT 0 and REFind(specialChars,testString) GT 0>
There's a match.
<cfelse>
There's no match.
</cfif>

Known Participant
April 15, 2010

Thanks. I'm almost done with this. I have

not programmed in years and very rusty and things are coming back to me now bit by bit.

Known Participant
April 13, 2010

Thanks. I meant special characters like @#$%^&*

Inspiring
April 15, 2010

Someone more clever than me might be able to do it with a single rexex, but I'd do it with 3.

<cfif Refind(something for capital letters) gt 0

and Refind(something for numbers) gt 0

and Refind(something that's neither a number nor a letter) gt 0>

good

<cfelse>

bad

Known Participant
April 15, 2010

Thanks Dan. That is what

I have done but I'm struggiling with the regular expression to check for capital

letters, number and special characters in the submitted form field.

Inspiring
April 13, 2010

Not sure what you mean by one character but, the function you want is REFind().