开发者

Help writing regular expression for validation in asp.net mc 2

I need my users to input very specific cell phone format cause my app will be sending sms to them

So, I need their cell phone formats to be like this

04AB-XXXXXXX

Where A can be either 1 or 2

and B can be either 2, 4 or 6

X can be from 0-9 There must be exactly 7 numbers (X) after 04AB

It must always start with 04

Examples:

04140000000 allowed

04240000000 allowed

04340000000 not allowed

14240000000 not allowed

04170000000 not allowed

So my property would need a regular expression validator but I wouldnt even know where to start... I just got this from a tutorial but it's for a different forma开发者_如何学JAVAt

[RegularExpression(@"^\$?\d+(\.(\d{2}))?$")]

this needs to be as strictly as possible because its gonna be used for text messaging. thanks in advance..


you need this:

^04[12][246][0-9]{7}$

That is withouth the "-"

^04[12][246]-[0-9]{7}$

is with the "-" and

^04[12][246]-?[0-9]{7}$

allows to use the "-" or leave it

the 0-9 can be replaced with \d like (I like [0-9] for beginners readability):

^04[12][246]-?[\d]{7}$

so it can become something like:

[RegularExpression(@"^04[12][246]-?[0-9]{7}$")] 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜