3 Replies Latest reply on Feb 15, 2013 11:22 AM by Carl Von Stetten

    Need help using Regex to parse street addresses

    Carl Von Stetten Adobe Community Professional & MVP

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


           <!--- address doesn't start with a number --->



      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.