Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel 11 1129
On Feb 26, 2:11 pm, "shapper" <mdmo...@gmail.comwrote:
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
if (?:) means a noncapturing group then you need a parenthesis
^?:(261|21|96|91)\s\d{7}$
Hi there again,
I believe it should work. I'm note sure how you utilized this regular
expression but if you're trying validate user input via regular expression
validation control
ValidationExpression="^(261|21|96|91)\s*\d{7}$"
should be enough. Otherwise, if you try to validate and get both area code
this might be an idea how to do that:
string pattern = @"^(261|21|96|91)\s(\d{7})$";
System.Text.RegularExpressions.Match match =
System.Text.RegularExpressions.Regex.Match(
txtPhone.Text, pattern);
if (match.Success)
{
string areaCode = match.Groups[1].Value;
string number = match.Groups[2].Value;
}
else
{
// not valid
}
--
Hope this helps
Milosz
"shapper" wrote:
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <md*****@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
On Feb 26, 2:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
http://groups.google.com/group/micro...fc7a34ed155ad8
On Feb 26, 1:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
Hi,
It really does not work. Please try:
' Create new regex
Dim regex As System.Text.RegularExpressions.Regex
regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ s
\d{7}$")
' Check if expression is a match
Response.Write(regex.IsMatch("961234567").ToString )
It returns False.
Any idea?
Thanks,
Miguel
On Feb 26, 1:49 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 26, 2:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
http://groups.google.com/group/micro...framework.aspn...
Hi Alexey,
I also tried your suggestion and a few others and it does not work.
Any idea?
Thanks,
Miguel
On Feb 26, 3:32 pm, "shapper" <mdmo...@gmail.comwrote:
On Feb 26, 1:49 pm, "Alexey Smirnov" <alexey.smir...@gmail.comwrote:
On Feb 26, 2:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
>news:11**********************@m58g2000cwm.googleg roups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel- Hide quoted text -
- Show quoted text -
http://groups.google.com/group/micro...framework.aspn...
Hi Alexey,
I also tried your suggestion and a few others and it does not work.
because of \s what mean a single space
regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ d{7}$")
The examples the OP gave were (I copy and paste):
261 1223346, 21 2334456
I assume that means a space is needed between the prefix and the last 7
digits.
So it still works for me on that basis.
Peter
Hi,
It really does not work. Please try:
' Create new regex
Dim regex As System.Text.RegularExpressions.Regex
regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ s
\d{7}$")
' Check if expression is a match
Response.Write(regex.IsMatch("961234567").ToString )
It returns False.
Any idea?
Thanks,
Miguel
You should have told us space is optional:
string pattern = @"^(261|21|96|91)\s*\d{7}$";
should do the job.
--
Milosz
"shapper" wrote:
On Feb 26, 1:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
Hi,
It really does not work. Please try:
' Create new regex
Dim regex As System.Text.RegularExpressions.Regex
regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ s
\d{7}$")
' Check if expression is a match
Response.Write(regex.IsMatch("961234567").ToString )
It returns False.
Any idea?
Thanks,
Miguel
Yep. Good specs. So hard to come by.
:)
Peter
"Milosz Skalecki [MCAD]" <mi*****@DONTLIKESPAMwp.plwrote in message
news:56**********************************@microsof t.com...
You should have told us space is optional:
string pattern = @"^(261|21|96|91)\s*\d{7}$";
should do the job.
--
Milosz
"shapper" wrote:
>On Feb 26, 1:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
Hi,
It really does not work. Please try:
' Create new regex Dim regex As System.Text.RegularExpressions.Regex regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ s \d{7}$")
' Check if expression is a match Response.Write(regex.IsMatch("961234567").ToString )
It returns False.
Any idea?
Thanks, Miguel
On Feb 27, 7:41 am, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
Yep. Good specs. So hard to come by.
:)
Peter
"Milosz Skalecki [MCAD]" <mily...@DONTLIKESPAMwp.plwrote in messagenews:56**********************************@m icrosoft.com...
You should have told us space is optional:
string pattern = @"^(261|21|96|91)\s*\d{7}$";
should do the job.
--
Milosz
"shapper" wrote:
On Feb 26, 1:44 pm, "Peter Bradley" <pbrad...@uwic.ac.ukwrote:
^((261)|(21)|(96)|(91))\s\d{7}$
works for me
Peter
"shapper" <mdmo...@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
Hello,
I need to create a REGEX which accepts only phone numbers.
The phone numbers start allways with 261, 21, 96 or 91 and have 7
numbers after it.
Something like. 261 1223346, 21 2334456, etc.
I tried the following but it is not working:
^(?:261|21|96|91)\s\d{7}$
How can I do this?
Thanks,
Miguel
Hi,
It really does not work. Please try:
' Create new regex
Dim regex As System.Text.RegularExpressions.Regex
regex = New RegularExpressions.Regex("^((261)|(21)|(96)|(91))\ s
\d{7}$")
' Check if expression is a match
Response.Write(regex.IsMatch("961234567").ToString )
It returns False.
Any idea?
Thanks,
Miguel
Thank You All.
It is working fine now.
Thanks,
Miguel This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Sriram |
last post by:
Hi,
I am having trouble matching a regex that combines a negated character
class and an anchor ($). Basically, I want to match all strings that
don't end in a digit. So I tried:
...
|
by: Bibe |
last post by:
I've been trying to get this going for awhile now, and need help. I've
done a regex object, and when I use IsMatch, it's behavior is quite weird.
I am trying to use Regex to make sure that a...
|
by: kevin |
last post by:
I am trying to strip the outermost html tag by capturing this tag with regex
and then using the string replace function to replace it with an empty
string. while stepping through the code, RegEx...
|
by: George Durzi |
last post by:
Consider the following HTML snippet. I want to extract the section shown
below.
<!-- some html -->
<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 border=0><?xml version=1.0
encoding=UTF-16?>
**...
|
by: tshad |
last post by:
Is there a way to use Regex inside of a tag, such as asp:label?
I tried something like this but can't make it work:
<asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")...
|
by: Chris |
last post by:
Hi Everyone,
I am using a regex to check for a string. When all the file contains is my
test string the regex returns a match, but when I embed the test string in
the middle of a text file a...
|
by: bullockbefriending bard |
last post by:
first, regex part:
I am new to regexes and have come up with the following expression:
((1|),(1|)/){5}(1|),(1|)
to exactly match strings which look like this:
1,2/3,4/5,6/7,8/9,10/11,12
...
|
by: Knight |
last post by:
Hi,
in the following program, compiled using gcc on Linux, and invoked
as
a.out '*' '111'
I get '111' matches '*'. What am I doing wrong?
#include <sys/types.h>
#include <stdio.h>
#include...
|
by: adamisko |
last post by:
Hello, what is wrong with this code, I want to divide string to pieces 4
chars length.
string tekst = "divide string to 4 chars pieces";
Regex regex = new Regex("(.{1,4})");
string substrings =...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |