0

I am trying to validate phone number with regEX. below is my requirement. 10 digits alpha/numeric, where an Alpha CHAR is in the 4th position (not including hyphen). For example: 586R410056

 NNN ANN NNNN

 (NNN) ANN NNNN

 NNN-ANN-NNNN

 (NNN) ANN-NNNN

 1NNN ANN NNNN

 1(NNN) ANN NNNN

 1NNN-ANN-NNNN

 1(NNN) ANN-NNNN

 NNN.ANN.NNNN

 (NNN-ANN-NNNN)

I came up with following regEX, but it's not working in angular form. regEX:

^[1]?\s?\(?\d{3}\)?[-.\s]?[a-zA-Z]{1}\d{2}[-.\s]?\d{4}\)?$
2
  • Why don't think of use ui-mask directive.. Which will provide the behavior you want.. Commented Nov 11, 2015 at 20:35
  • First, try /^1?\s?\(?\d{3}\)?[-.\s]?[a-zA-Z]\d{2}[-.\s]?\d{4}\)?$/ without /g modifier. Next, try removing novalidate. Have a look at this plunkr. Commented Nov 11, 2015 at 21:16

1 Answer 1

1

You can try the following:

Regex

/1?[\ \.\(]?[N]{3}\)?[]\ \-\.][A][N]{2}[\ \-\.][N]{4}\)?/g

(Just replace the Ns with [0-9] and A with [0-9a-zA-Z]).

Explanation:

screenshot

See working example at https://regex101.com/r/dX1lL0/1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.