-3

I want to validate 10 digit number which should start with 91 or +91

   var expr = new Regex(@"^((\+){0,1}91(\s){0,1}(\-){0,1}(\s){0,1}){0,1}9[0-9](\s){0,1}(\-){0,1}(\s){0,1}[1-9]{1}[0-9]{7}$");

This here only matches 10 digit which start with 9.

input: 919234521098,9876543210;+919876543211;919876543212

op :919234521098,+919876543211;919876543212

Thanks

Rohit
  • 10,056
  • 7
  • 50
  • 82

9 Answers9

1

try this one:

var regex = new Regex(@"\+?91\d{8}")
HungDL
  • 493
  • 2
  • 11
1

This one should do the trick

\+?91\s?\d{8}

It will match both +9112345678, 9112345678, +91 12345678 and 91 12345678

Explanation:

  • +?91 will match 91 or +91(note the ?, it will make the character before optional)
  • \s? will allow to have a space after 91
  • \d{8} matches 8 digits
Maarten Peels
  • 1,002
  • 1
  • 13
  • 29
1

This expression works:

\+?91\d{8}

What it does:

  • \+?: an option + (\ escapes the +. The ? makes it optional)
  • \d{8}: 8 digits
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
1

Here is the regex:

https://regex101.com/r/mB4rX2/1

^\+?91[0-9]{8}$
TomerM
  • 335
  • 1
  • 7
0

You can try this. It would match a 10 digit mobile number starting with either +91 or 91.

^[+]*91\d{10}$
Praveen Paulose
  • 5,741
  • 1
  • 15
  • 19
0
^[+91]+\d{8}

This should work.

  • Hiya there, while this may well answer the question, please be aware that other users might not be as knowledgeable as you. Why don't you add a little explanation as to why this code works? Thanks! – Vogel612 Mar 31 '15 at 10:27
0

^\+?91[7,8,9]{1}[0-9]{9}$ This will check for + is there or not. Then for 91 and then first digit will be between 7,8,9 and then last 9 digits.

Sahil Gupta
  • 13
  • 1
  • 8
0
<td>
                    <asp:TextBox ID="txtSMSMNo" runat="server"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                        ControlToValidate="txtSMSMNo" ErrorMessage="Enter Mobile No"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidatortxtMob" runat="server" SetFocusOnError="true"
                        ControlToValidate="txtSMSMNo" ErrorMessage="Please enter valid Mobile No." ValidationGroup="Valid"
                        ForeColor="Red" ValidationExpression="^[789]\d{9}$"> </asp:RegularExpressionValidator>
                </td>
-1
used this code solve your problem


<asp:RegularExpressionValidator 
ID="RegularExpressionValidatortxtMob" 
runat="server"
SetFocusOnError="true"
ControlToValidate="txtSMSMNo" 
ErrorMessage="Please enter valid Mobile No."
ValidationGroup="Valid" 
ForeColor="Red"
ValidationExpression="^[789]\d{9}$">
</asp:RegularExpressionValidator>
Alan Moore
  • 73,866
  • 12
  • 100
  • 156