pfeifest said:
Hello-
How would I validate the following statement in a REGEX validation?
***********************
a 7-digit number starting with an 8 or an 8-digit number starting with
a 5
***********************
the actual regular expressions would be (i believe) this:
^(8\d{6})$
^(5\d{7})$
.... i think. definitely something like that. You'll need to escape the
backslashes when you actually build the Pattern object.
if it will help you later, i'll explain. they read like this:
^ - at the very beginning of the string,
( - start remembering what you match,
8 - look for a number eight,
\d{6} - followed by 6 other digits,
) - don't remember anything after this,
$ - and only if the number touches the end of the string.
similarly for the second regex.
If you don't necessarily want to match these numbers on their own, for
instance, if they're part of a sentence, remove the ^ and $, and maybe
add spaces before the 8 and after the \d{6}.
I highly recommend O'Reilly's "Mastering Regular Expressions" by Jeffrey
Friedl. I used to work with him at Yahoo! and the dude knows regular
expressions better than anyone I've ever met.
Hope that helps.