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

Need help using Regex to parse street addresses

Guide ,
Feb 15, 2013 Feb 15, 2013

Copy link to clipboard

Copied

Let me start off by stating three things:

  1. I suck at regex,
  2. I've googled this and didn't come up with an answer, and
  3. 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.

TOPICS
Advanced techniques

Views

1.4K

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

LEGEND , Feb 15, 2013 Feb 15, 2013

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

Votes

Translate

Translate
LEGEND ,
Feb 15, 2013 Feb 15, 2013

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

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
Guide ,
Feb 15, 2013 Feb 15, 2013

Copy link to clipboard

Copied

LATEST

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.

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 ,
Feb 15, 2013 Feb 15, 2013

Copy link to clipboard

Copied

Oh, and if you're not using the sub-expression, you don't need the parentheses.

--

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
Resources
Documentation