Copy link to clipboard
Copied
Let me start off by stating three things:
I have a form with an autocomplete input that allows a user to enter street addresses (either in full like "123 Main St, Mayberry" or in part like "123 Main St" or "Main St" or "Main St, Mayberry". I need to tell if the user has provided a street number or not at the beginning of the value they enter into the input. I'm trying to test the input value with this code:
<cfif ReFind("^([0-9]{1-5})",q)>
<!--- address starts with a number --->
<cfelse>
<!--- address doesn't start with a number --->
</cfelse>
q is the input value being passed into my code from the autocomplete function.
x should be either 0 (if the input value doesn't start with a number) or a positive integer (if the input value does start with a number).
Basically, I just need to know if the input value starts with one to five digits.
I suppose I could just do something like:
<cfif Val(q)>
Am I better off using a regex, and if so, what am I doing wrong with the one I've tried?
-Carl V.
It's {1,5}, not {1-5}.
Maybe read my series of articles on CF regexes to help you get better up to speed with them:
http://adamcameroncoldfusion.blogspot.co.uk/2012/12/regular-expressions-in-coldfusion-part.html
--
Adam
Copy link to clipboard
Copied
It's {1,5}, not {1-5}.
Maybe read my series of articles on CF regexes to help you get better up to speed with them:
http://adamcameroncoldfusion.blogspot.co.uk/2012/12/regular-expressions-in-coldfusion-part.html
--
Adam
Copy link to clipboard
Copied
Oh man do I feel stupid! I read the Adobe docs several times, and understood I needed a comma there, but I had a brain fart when I actually typed my code. Thanks for the minor *headslap*!
I had tried it without the parantheses before, and had added them when trying to troubleshoot. I'll remove them from my working code.
And I will check out your blog series on Regex.
-Carl V.
Copy link to clipboard
Copied
Oh, and if you're not using the sub-expression, you don't need the parentheses.
--
Adam