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
  • 607,720
  • 39
  • 448
  • 563
JianYA
  • 2,750
  • 8
  • 60
  • 136

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
  • 11,506
  • 16
  • 62
  • 109
trk
  • 2,106
  • 14
  • 20