Need help using Regex to parse street addresses
Let me start off by stating three things:
- I suck at regex,
- I've googled this and didn't come up with an answer, and
- I'm on ColdFusion 10
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.
