Solved

Regular expression ignoring white space

Posted on 2010-09-11
5
569 Views
Last Modified: 2012-06-27
I have a regular expression
^\d{15,}$
which I use to check for a string of >= 15 figits e.g. 1868477631712341234
I now need to be able to validate the same string when it may contain spaces and I want to ignore the spaces. So that
1868 477 6317 1234 1234
is also a valid string.
0
Comment
Question by:PugwashXP
  • 2
  • 2
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 33652347
^\s*(\d\s*){15,}$
0
 
LVL 4

Expert Comment

by:Zxeses
ID: 33652705
Ozo's solution is almost valid, except the spaces count against the 15 count.  You are going to need to do some scripting validation post regex.

I would suggest:

[\d\s-]+
Digit, space or dash

Then in scripting:

Use a regex to replace any non 0-9 characters with null: [^0-9]
Then test the result to make sure your string length is 15.

If you need more specific help with a given language, let me know.
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 33653512
^\s*(\d\s*){15,}$
requires >= 15  digits
[\d\s-]+
requires no digits
Removing non digits is still a good idea before doing any other processing on the validated result.
0
 

Author Closing Comment

by:PugwashXP
ID: 33653697
Thanks - works just right
0
 

Author Comment

by:PugwashXP
ID: 33653700
Thanks guys - all I needed was the regex for validation - processing was not the issue.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need Regular Expresionin quarter hours 3 36
URL's dynamic 4 34
SQL query to extract a portion of a field 6 75
RegEx Help - open to other simple suggestions 8 35
by Batuhan Cetin Regular expression is a language that we use to edit a string or retrieve sub-strings that meets specific rules from a text. A regular expression can be applied to a set of string variables. There are many RegEx engines for u…
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

948 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now