Click here to Skip to main content
14,920,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want a regular expression to validate this format of pnone number any help

961_(71 or 72 or 76 or 79 or 3)_and 6 digits number [0-9]

example: 96171648262,9613635241



"how could i use it in to validate a string"

Dim validate As New Regex("961(71|72|76|79|3)\d{6}")
Dim inp As String = "96171648262"
If validate.Match(inp).Success Then
End If
[no name] 4-Sep-13 4:39am
how could i use it in to validate a string
OriginalGriff 4-Sep-13 5:00am
Answer updated
[no name] 4-Sep-13 5:18am
thanks it works
OriginalGriff 4-Sep-13 5:24am
You're welcome!
[no name] 4-Sep-13 5:30am
it fail on this number 96130000560.. this number has 7 digits after the (3) it should have 6 only
OriginalGriff 4-Sep-13 5:36am
Ah! Try adding start and end marker to the string:
[no name] 4-Sep-13 5:40am
it didnt work ... it took all the numbers as invalid even if the number is valid
OriginalGriff 4-Sep-13 6:21am
Show me exactly what code you are using - including where you get the input string from.
use this code

Public  Function ValidatePhone(sPhone As String) As Boolean
    Dim sReg As New System.Text.RegularExpressions.Regex("961(71|72|76|79|3)\d{6}")
    If sReg.IsMatch(sPhone) Then
        Return True
        Return False
    End If
End Function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900