Copy link to clipboard
Copied
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
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]"
...Copy link to clipboard
Copied
Not sure what you mean by one character but, the function you want is REFind().
Copy link to clipboard
Copied
Thanks. I meant special characters like @#$%^&*
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
To get the answer quickly, this might help. http://www.regular-expressions.info/reference.html
To learn how to write regular expression patterns, this might help. http://www.regular-expressions.info/tutorial.html
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Thank you BKBK.
Cheers
Copy link to clipboard
Copied
No thanks.