Monday, August 30, 2010

Regular Expression Minimum Digits / Phone Number

This regular expression will check string that contains at least 7 number of digits:

(\D?\d\D?){7,}

For example:

123456 = false
12ad34g5a6 = false
1234567 = true
1m2m3m4m5m6m7 = true

This can also be used to validate or check phone numbers (at least 7 digits)

(([\(\-\+\s]?\d[\)\-\+\s]?){7,})\d?$

(+971) 372 - 6202
(+971) 3726202
(971) 3726202
971-372-6202
9713726202

No comments:

Post a Comment