0

I have this Regular Expression:

^([^6]*)6

I want it to match ONLY the first character and make sure its a 6. E.g.

60123456789

It should return 1 match

0123456789 should return 0 matches

How can I do this?

Currently the results it returns in my application is: 601234567890 returns an error

EDIT: This is a data annotation above my ViewModel property

[RegularExpression("^([^6]*)6", ErrorMessage = "Phone Numbers must start with a 6")]
Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
JianYA
  • 2,988
  • 6
  • 49
  • 104

1 Answers1

0

I think this should work:

'6123'.match(/^6(.+)$/)[0]

Where, '6123': is any number. For numbers starting with 6 it will match else it would return null.

Let me know if that works.

Ari Seyhun
  • 10,213
  • 15
  • 54
  • 98
trk
  • 1,786
  • 11
  • 18