samedi 9 mai 2015

regular expression ruby phone number

I'm trying to figure out how to write my own regex.

I made a list of viable phone numbers and non-viable ones and trying to make sure the viable ones are included but I can't figure out how to finish it up.

Allowed list

0665363636 //
06 65 36 36 36 //
06-65-36-36-36 //
+33 6 65 36 36 36

Not allowed

06 65 36 36 //
2336653636 //
+3366536361 //
0065363636 

I messed around with it a bit and I currently have this:

[0+][63][6 \-3][56\ ][\d{1}][\d \-]\d{2}[\d{1} \-]\d\d? ?\-?\d?\d? ?\d?\d?$

This blocks out number 2 and 4 of the non allowed but I can't seem to figure out how to block the other ones out.

Should I put a minimum amount of numbers? If so how would I do this.

Aucun commentaire:

Enregistrer un commentaire