Regular Expressions 101

Community Library Entry

0

Regular Expression
ECMAScript (JavaScript)

/
^(?=[\d-]{3,18}$)\d{1,6}-\d*[-]?\d+$
/
g

Description

Regular expression to check complex account no of max length of 18

Conditions:

  1. max length of account no. is 18 chars
  2. 1 hiphen is compulsary
  3. Before 1st hiphen there should be digits between range 1-6
  4. If second hiphen introduces then there must be atleast 1 digit in between them and one digit after second hiphen
  5. If there is only 1 hiphen then after 1st hiphen there must be 1 digit

RegEx for above conditions

^(?=[\d-]{3,18}$)\d{1,6}-\d*[-]?\d+$

Submitted by anonymous - 7 years ago