473,672 Members | 2,597 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

See If You Can Modify This Simple Regular Expression

I currently have a regular expression that will match textbox input for
phone numbers formatted as ###-###-####.

The expression is...

\d{3}-\d{3}-\d{4}

How can I modify this to accept the same pattern (ten digits) OR
###-#### (seven digits)?

May 26 '06 #1
3 1085
Joey wrote:
I currently have a regular expression that will match textbox input for
phone numbers formatted as ###-###-####.

The expression is...

\d{3}-\d{3}-\d{4}

How can I modify this to accept the same pattern (ten digits) OR
###-#### (seven digits)?


1) This will match a telephone number anywhere in the input. If you're
scanning a body of text for phone numbers, use it. If you're validating
user input, add ^ to the start and $ to the end...

2) In answer to your question:
(\d{3})?-\d{3}-\d{4}

or with both:
^(\d{3}-)?\d{3}-\d{4}$

Damien

May 26 '06 #2

"Joey" <jo*********@to pscene.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
I currently have a regular expression that will match textbox input for
phone numbers formatted as ###-###-####.

The expression is...

\d{3}-\d{3}-\d{4}

How can I modify this to accept the same pattern (ten digits) OR
###-#### (seven digits)?

The | is used for "or" so it would be something like
\d{3}-\d{3}-\d{4}|\d{3}-\d{4}
May 26 '06 #3
Thanks. That worked.

May 26 '06 #4

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

Similar topics

3
2139
by: EFP | last post by:
Can anyone help me with a simple regular expression problem. All that I want to do is take a list of known data and extract a particular section of the string to form a new list. Here is my code snipet: my $fh = new FileHandle('c:\Units.txt') ; ## sucks up my work file my @lines1 = <$fh>; ## assigns the filehandler contents to @lines1 foreach $string (@lines1) ## extract each line from @lines and put it
5
2083
by: Swarna | last post by:
Hi all, Can anyone help me with this ? I am using scp in python to copy a html file on remote server, to my local machine. Now, i need to update this html file in my local machine ( by adding a new Hyperlink to the existing table od hyperlinks ) and copy it back (overwriting the old copy ) to the remote server. Thanks, for your time !
4
3222
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 over each document, find out if it contains a header and/or a footer and extract only the main content part. The headers and the footers have no specific format and I have to detect and remove them using a list of strings that may appear as...
18
3027
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How ??
11
11929
by: tlyczko | last post by:
Hello Rob B posted this wonderful code in another thread, http://groups.google.com/group/comp.lang.javascript/browse_thread/thread/c84d8538025980dd/6ead9d5e61be85f0#6ead9d5e61be85f0 I could not figure out how to reply to the thread per se using Google Groups and so please forgive me for cutting and pasting (I emailed him but he may not have time to check his email), and I am hoping someone might be able to tell me how I can change this...
7
3819
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I want to avoid that. My question here is if there is a way to pass either a memory stream or array of "find", "replace" expressions or any other way to avoid multiple copies of a string. Any help will be highly appreciated
25
5147
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART (CONDUCTION DEFECT) 37.33/2 HEART (CONDUCTION DEFECT) WITH CATHETER 37.34/2 " the expression is "HEART (CONDUCTION DEFECT)". How do I gain access to the expression (not the matches) at runtime? Thanks, Mike
4
2474
by: drasko | last post by:
Hi all. I need to code simple and fast int regexp_match(char *regexp, char *string) function that will follow the expression regexp, and see if there is a matching in the string. If there is, it will return 1 (TRUE). Are there some examples I can see, do you have ideas how to start with this, and so on... GNU C regexp is to big and complicated for me, it takes a lot of space (i need this for the use in embedded system). I'll...
1
4376
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find the first regular expression that matches the string. I've gor the regular expressions ordered so that the highest priority is first (if two or more regular expressions match the string I want the first one returned) The code that does this has...
0
8486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8608
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7446
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5705
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4227
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2063
muto222
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.