Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expressions For skype name in PHP

Tags:

regex

php

Please I want to validate the skype name using regular expressions in PHP.

NOTE: It must be between 6-32 characters, start with a letter and contain only letters and numbers (no spaces or special characters).

like image 655
Alpha Avatar asked Oct 05 '12 13:10

Alpha


2 Answers

This pattern should work for you:

[a-zA-Z][a-zA-Z0-9\.,\-_]{5,31}

This will match a leading letter, followed by any alpha-numeric combination up to a total of between 6 - 32 characters (for the entire string).

You can use this in PHP with:

if (preg_match('/^[a-z][a-z0-9\.,\-_]{5,31}$/i', $name)) {
    // you have a valid name!
}

Note, in the preg_match(), I added the i regex option to ignore case. Also, I lead the pattern with ^ to signify that the pattern has to start at the beginning of the string and I ended with a $ to signify that the pattern has to finish at the end of the string.

like image 153
newfurniturey Avatar answered Nov 08 '22 02:11

newfurniturey


This will do the job:

preg_match( '~^[a-z][a-z0-9]{5,31}$~i', $text)
like image 33
Vyktor Avatar answered Nov 08 '22 02:11

Vyktor