Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
the phone number should be
10 numeric digits, must start with 04 or 02


What I have tried:

Im a new learner to regex so I don't really know how to get started with this
Posted
Updated 14-Apr-21 5:52am
v3

Try:
^0(2|4)\d{8}$

But that shouldn't be difficult even for a beginner. Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.
 
Share this answer
 
Quote:
Im a new learner to regex so I don't really know how to get started with this

What have you done so far ? Are you able to make a RegEx validationd 1 single digit ? 2 digits ? more
Show your work and explain where you are stuck.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
Online regex tester and debugger: PHP, PCRE, Python, Golang and JavaScript[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
This site also show the Regex in a nice graph but can't test what match the RegEx: Regexper[^]
 
Share this answer
 
v2

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