Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
RegEx
Message
De
30/10/2012 03:31:54
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Re: RegEx
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01555501
Message ID:
01556034
Vues:
51
This message has been marked as a message which has helped to the initial question of the thread.
>How hard it is to construct a phone number validator? All phone RegEx validaitors I found in StackOverflow seem to not let me enter a valid number, e.g.
>
>(999) 123-1288 - Ok
>888 123-9999
>
>900 1111
>
>9001111
>
>I think these are all valid numbers. I am not sure if I can handle all of them with a RegEx expression or better to write validate function.
>
>

Don't spend time googling for expressions. Analyse the examples and the pattern follows

The examples tell me
&& (a) three digits, optionally in ()
&& (b) space char
&& (c) three digits
&& (d) space or hyphen or nothing
&& (e) four digits
&& (f) trailing space

&&  or

&& (c) three digits
&& (d) space or hyphen or nothing
&& (e) four digits
&& (f) trailing space
You can take out (f) trailing space, if needed - depends on how your data is structured

Do not forget the ^ and $ anchors in the pattern
loRegExp = CREATEOBJECT("VBScript.Regexp")
loRegExp .pattern = '^((\(\d{3}\)|\d{3})\s?)?\d{3}[-\s]?\d{4}\s*$'

&& last line is invalid
text to s noshow pretext 7
(999) 123-1288
888 123-9999

900 1111

9001111
900-1111
900111
endtext

naa = alines(aa, s, 5, chr(0x0d) + chr(0x0a))

for each x in aa
	 ? x, ' ', loRegExp.Test(x)
endfor
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform