1

i am trying to validate if string starts with letter k, followed by anything

Expected output :

khtjk
k1234
kq12g

i followed this and this, but it doesnt allow anything after k

this is what i tried :

[RegularExpression("^k", ErrorMessage = "Sorry, enter correct bill no")]
public string StoreBillNo { get; set; }

any help would be great.

Community
  • 1
  • 1
Shaiju T
  • 6,201
  • 20
  • 104
  • 196
  • @Avinash Raj, thank you that works fine, but to check both capital and small k, post as answer if required – Shaiju T Mar 12 '15 at 09:28

1 Answers1

3

You have to use this regex for capital and small case:

^[kK].*

or use ignore case :

/^k.*/i

OR

"(?i)^k.*"
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
  • thank you works great, stackoveflow, wants me to wait for 2 minutes to accept your answer, just waiting, 33 seconds more – Shaiju T Mar 12 '15 at 09:36
  • oh you copied my answer. For case-insesitivity, you could use `(?i)` modifier at the start also. – Avinash Raj Mar 12 '15 at 09:38
  • @AvinashRaj it is the simplest regex that OP needed so there's no need to copy but yes you put it as comment so you think that i copied..:) – Ehsan Sajjad Mar 12 '15 at 09:40
  • @EhsanSajjad no probs :), asked just for fun :-) – Avinash Raj Mar 12 '15 at 09:41
  • @AvinashRaj FYI just telling you that i also got interetsed to learn regex so i strated to look in regex tag questions ..:) – Ehsan Sajjad Mar 12 '15 at 09:42
  • keep up the good work.. Try to post regex answers on very first. Because there are many regex gurus here. – Avinash Raj Mar 12 '15 at 09:43
  • hi, both , for ignore case i tried these three, `/^k.*/i` and `/^k.*/?i` and this `(?i)^k.*`, but doesn't work – Shaiju T Mar 12 '15 at 09:45
  • 1
    @stom first one is fine as it is just one letter so you can afford to add captial and small both – Ehsan Sajjad Mar 12 '15 at 09:53
  • yes first one works fine, it was simple, i tried, but failed, but now with your help i could learn and do, thanking both of you for guiding thus far – Shaiju T Mar 12 '15 at 09:57