regex - Regular Expression Validation for a Phone no that will accept nos,dashes and + -


I just need a regular expression that will validate the phone not entered in the text box. This textbox can only allow numbers, dashes (-) and plus (+) and can be up to 15 characters and a minimum of 11 characters. (+) Can (Optional) come only on starting the phone number.

Please answer.

The answer to your question is on:

  \ +? [\ D]] {1,13}   
  • \ +? means "a '+' character of zero"
  • [\ d -] {1,13} means 1 to 13 digits or hyphen "

    However, I think that you should use some more instructions. At least 8 digits may be required and the hyphen can not be either first or last:

      ^ (? = (. * \ D) {8,13}) \ +? (?! -) [\ d -] * (? & Lt;! -) $    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -