Mobile Number Regex

Jassim Al Rahma 1,616 Reputation points
2023-02-23T20:29:02.3266667+00:00

Hi,

How can I have a Regex that validates a local number that:

1. Starts with 05

2. Should be a total of 10 numbers.

Thanks,

Jassim

Developer technologies | .NET | .NET MAUI
Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anonymous
    2023-02-24T05:21:36.8+00:00

    Hello,

    You can do this by string MobileRegex = @"^05\d{8}$";.

    ^ matches the beginning of the string.

    05 will be a simple and plain exact match.

    \d will match any digit.

    {8} will repeat the previous expression (\d in this case) exactly 8 times.

    $ matches the end of the string.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Alessandro Caliaro 4,196 Reputation points
    2023-02-23T20:50:48.6533333+00:00

    Maybe this

    /05[0-9]{8}/gm


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.