Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 624
  • Last Modified:

Regular expression ignoring white space

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
PugwashXP
Asked:
PugwashXP
  • 2
  • 2
1 Solution
 
ozoCommented:
^\s*(\d\s*){15,}$
0
 
ZxesesCommented:
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
 
ozoCommented:
^\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
 
PugwashXPAuthor Commented:
Thanks - works just right
0
 
PugwashXPAuthor Commented:
Thanks guys - all I needed was the regex for validation - processing was not the issue.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now