Reputation: 85
I have one registration form, I don't want people to register login username with unicode characters. How can i put server side validation PHP + client side validation javascript or jquery.
Please kindly help me out. Thank you.
Upvotes: 0
Views: 2852
Reputation: 490243
Well do you mean outside of normal ASCII range?
You could implement one of the many seemsLikeUtf8()
function floating around on the net.
Or do a quick regular expression
if ( ! preg_match('/^[a-z0-9-]+$/i', $username)) {
echo 'error';
}
Upvotes: 1
Reputation: 72658
A simple regular expression would do:
if (!username.match(/^[a-zA-Z0-9_+]+$)) {
alert("invalid username");
}
This will check that the username contains only the characters a-z (upper and lower case), the digits 0-9, '_' and '+'. If you want to extend it to allow other characters, you'll just need to look up a bit more about regular expressions.
On the server-side, you'd do exactly the same thing, since PHP also supports regular expressions.
Upvotes: 0