0

I'm trying to use the phone number regex that this person submitted but I can't figure out why it's not working.

<cfelseif NOT REFIND("^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$",contactphone) >

It's giving me an error around (\d+) at the end. (I'm new to ColdFusion and using RegEx)

Community
  • 1
  • 1
  • There is a pound sign `#` in your regular expression so you probably need to escape that for ColdFusion by doubling it up as `##`. – Miguel-F Jun 06 '13 at 20:34

1 Answers1

1

In ColdFusion # is used to output a string. If you're cfelseif is within cfoutput tags you need to escape the # by using ##. Updating your regEx to the below format should solve your issue.

<cfelseif NOT REFIND("^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:##|x\.?|ext\.?|extension)\s*(\d+))?$",contactphone) >
Matt Busche
  • 14,216
  • 5
  • 36
  • 61
  • 1
    @confusedStudent: If this answer solved your problem, you should indicate that to future readers by "accepting" it. See: [What does it mean when an answer is "accepted"?](http://stackoverflow.com/helpcenter/accepted-answer) – ale Jun 07 '13 at 14:42