0

Possible Duplicate:
Regular expression for SSN and phone number

^(?!.*(\\d{16})|.*(\\d{9})|.*(\\d{3}-\\d{2}-\\d{4})|.*(\\d{3}-\\d{3}-\\d{3})).*

The above regex does not allow SSN and phone number in the string. But It is also not allowing \n (enter character). If user enters two lines of text by hitting enter this regex fails.

Community
  • 1
  • 1
user679526
  • 845
  • 4
  • 16
  • 39
  • I need an answer, so I reposted the question. What is wrong in it. – user679526 Jan 14 '13 at 17:29
  • What's wrong is that you're duplicating your "question". The Stack Exchange community heavily frowns upon purposefully duplicated content. Edit your first question to make it a coherent question and it might be re-opened. –  Jan 14 '13 at 17:31
  • Oh, by the way, deleting your own questions can also trigger a question ban. –  Jan 14 '13 at 17:32

1 Answers1

2

By default the period (.) does not match newline characters. If you can't configure DOTALL mode, per this SO answer, consider ending with [\s\S]* (any number of characters that are or aren't whitespace) rather than .*.

Community
  • 1
  • 1
Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251
  • If user enters text new line and then 123-123-123. This content is still validated as correct even though 123-123-123 is an invalid format. – user679526 Jan 14 '13 at 16:30
  • @user679526 Did you fix every appearance of `.*`, rather than just the final one? Your complicated negative assertion means that you'll have to be very verbose in your replacement. Alternatively, look for a way to say "if you find this regular expression, the string is invalid", which will likely be much simpler and easier to maintain. – Jeff Bowman Jan 14 '13 at 19:16