Infopath claims my regex is not valid pattern but it's straight from a book. Why? - InfoPath Dev
in

InfoPath Dev

Infopath claims my regex is not valid pattern but it's straight from a book. Why?

Last post 08-24-2012 02:19 AM by IceThatJaw. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-23-2012 05:46 PM

    Infopath claims my regex is not valid pattern but it's straight from a book. Why?

    I don't particularly like the built in phone number regex because it only matches one format. I have a niftly regex handbook with a great one for US phone numbers. Regex = \(?[2-9]\d\d\)?[ -]?[2-9]\d\d-\d{4}

    This allows for 000-000-0000, (000) 000-0000, and (000)000-0000.

     When I make a rule and do a match based on this custom pattern it says it's not a valid pattern when I try to enter it. Any ideas?

  • 08-23-2012 11:47 PM In reply to

    Re: Infopath claims my regex is not valid pattern but it's straight from a book. Why?

    Looks like you need to use a backslash before hyphens.  Perhaps the people who designed this regex parser thought it would be better that way because hyphens sometimes have a semantic meaning in regular expressions.
    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 08-24-2012 02:19 AM In reply to

    Re: Infopath claims my regex is not valid pattern but it's straight from a book. Why?

     Nice catch. I updated the regex to also handle a decimal format.

     [\(.]?[2-9]\d\d[\).]?[ \-]?[2-9]\d\d[\-.]\d{4}  

    Matches:

     200-200-0000

    (200)200-0000

    (200) 200-0000

    200.200.0000

     

    Thanks and everyone should definitely use this expression rather than the built in one for US phone numbers. 

    Thanks. 

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.