473,473 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help with regular expression

Joe
Hi,

I am stuggling with building a regular expression that would allow only 0-9,
+, -,_, space, (, ). Can someone guide me. This is for validating phone using
JavaScript in my asp page.

Thanks for you time,

Joe

Nov 19 '05 #1
3 951
Don't recreate the wheel. Search http://www.regexlib.com/Default.aspx.
You're bound to find what you're looking for.

HTH
----
http://www.davefancher.com
"Joe" wrote:
Hi,

I am stuggling with building a regular expression that would allow only 0-9,
+, -,_, space, (, ). Can someone guide me. This is for validating phone using
JavaScript in my asp page.

Thanks for you time,

Joe

Nov 19 '05 #2
hello
i think this code will help. U have to change the code a little bit
according to ur situation. in my case if the phone no. is valid then it will
return true. u can send return the validated phone no or error message.
Note: in this function i have use a string variavble ErrorMessage which is
member of the class. You have to handle it urself.

for any more help you can contact me via emal ---> cu*****@hotmail.com

public bool Validity( string PhoneNo)
{
bool flag = false;
if( PhoneNo[0] >= '0' && PhoneNo[0] <= '9' || (PhoneNo[0] == '+') )
{
for(int i = 1; i < PhoneNo.Length; i++)
{
if( (PhoneNo[i] >= '0' && PhoneNo[i] <= '9') || (PhoneNo[i] == '_') ||
(PhoneNo[i] == '-') || (PhoneNo[i] == ' ') )
flag = true;
else
{
this.ErrorMessage = "The character \"" + email[i] + "\" is not allowed
in the PhoneNo";
flag = false;
break;
}
}
}
else
{
this.ErrorMessage = "First character must be between 0-9 or it may be + ";
flag = false;
}
return flag;
}


"Joe" wrote:
Hi,

I am stuggling with building a regular expression that would allow only 0-9,
+, -,_, space, (, ). Can someone guide me. This is for validating phone using
JavaScript in my asp page.

Thanks for you time,

Joe

Nov 19 '05 #3
hello
i think this code will help. U have to change the code a little bit
according to ur situation. in my case if the phone no. is valid then it will
return true. u can send return the validated phone no or error message.
Note: in this function i have use a string variavble ErrorMessage which is
member of the class. You have to handle it urself.

for any more help you can contact me via emal ---> cu*****@hotmail.com

public bool Validity( string PhoneNo)
{
bool flag = false;
if( PhoneNo[0] >= '0' && PhoneNo[0] <= '9' || (PhoneNo[0] == '+') )
{
for(int i = 1; i < PhoneNo.Length; i++)
{
if( (PhoneNo[i] >= '0' && PhoneNo[i] <= '9') || (PhoneNo[i] == '_') ||
(PhoneNo[i] == '-') || (PhoneNo[i] == ' ') )
flag = true;
else
{
this.ErrorMessage = "The character \"" + email[i] + "\" is not allowed
in the PhoneNo";
flag = false;
break;
}
}
}
else
{
this.ErrorMessage = "First character must be between 0-9 or it may be + ";
flag = false;
}
return flag;
}


"Joe" wrote:
Hi,

I am stuggling with building a regular expression that would allow only 0-9,
+, -,_, space, (, ). Can someone guide me. This is for validating phone using
JavaScript in my asp page.

Thanks for you time,

Joe

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Steve | last post by:
Hello, I am writing a script that calls a URL and reads the resulting HTML into a function that strips out everthing and returns ONLY the links, this is so that I can build a link index of various...
5
by: Bradley Plett | last post by:
I'm hopeless at regular expressions (I just don't use them often enough to gain/maintain knowledge), but I need one now and am looking for help. I need to parse through a document to find a URL,...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
6
by: JohnSouth | last post by:
Hi I've been using a Regular expression to test for valid email addresses. It looks like: \w+(\w+)*@\w+(\w+)*\.\w+(\w+)* I've now had 2 occassions where it has rejected and email address...
3
by: Joe | last post by:
Hi, I have been using a regular expression that I don’t uite understand to filter the valid email address. My regular expression is as follows: <asp:RegularExpressionValidator...
1
by: Rahul | last post by:
Hi Everybody I have some problem in my script. please help me. This is script file. I have one *.inq file. I want run this script in XML files. But this script errors shows . If u want i am...
3
by: Zach | last post by:
Hello, Please forgive if this is not the most appropriate newsgroup for this question. Unfortunately I didn't find a newsgroup specific to regular expressions. I have the following regular...
6
by: deepak_kamath_n | last post by:
Hello, I am relatively new to the world of regex and require some help in forming a regular expression to achieve the following: I have an input stream similar to: Slot: slot1 Description:...
14
by: Chris | last post by:
I need a pattern that matches a string that has the same number of '(' as ')': findall( compile('...'), '42^((2x+2)sin(x)) + (log(2)/log(5))' ) = Can anybody help me out? Thanks for any help!
3
by: Mr.Steskal | last post by:
Posted: Wed Jul 11, 2007 7:01 am Post subject: Regular Expression Help -------------------------------------------------------------------------------- I need help writing a regular...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.