0

I want to put a validation in angular 6. It should contain alpha numeric characters. Either Alphabets or Numeric, 3 to 9 digits only. It should start with 1 if it is Numeric.

Can anybody help me with these validation ?

Validators.pattern("[^[A-Z a-z | \d 1 ] ]")

Can anybody please help me in this?
Toto
  • 89,455
  • 62
  • 89
  • 125
sai
  • 487
  • 1
  • 7
  • 16

1 Answers1

1

You could match either 9 digits, starting with 1 and followed by 8 digits 0-9 or match a char a-zA-Z and repeat that 9 times using an alternation

^(?:1\d{2,8}|[A-Za-z]{3,9})$

Explanation

  • ^ Start of string
  • (?: Non capture group
    • 1\d{2,8} Match 1 followed by 2-8 digits to match 3-9 times
    • | Or
    • [A-Za-z]{3,9} Match a char a-zA-Z and repeat that 3-9 times
  • ) Close group
  • $ End of string

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70