my dog learned polymorphism
The moose likes PHP and the fly likes Javascript validation in PHP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » PHP
Bookmark "Javascript validation in PHP" Watch "Javascript validation in PHP" New topic

Javascript validation in PHP

bala kan
Ranch Hand

Joined: Aug 20, 2012
Posts: 44
Hi Guys,

I am doing a login page which contains user name and password..

I need to validate the username using regular expression
the criteria is as follows:
1)It can contain either alphabets, special characters(-,'',_) or numbers..
2)length should be minimum of 8 characters and maximum of 20 characters..

so, my codings to validate the username is

"if(!(/^[a-zA-Z0-9/-_ ]{8,20}$/).test(uid))" does not validate the above mentioned criteria.. please clarify me

Thanks in advance


Nick Charles
Ranch Hand

Joined: Oct 09, 2011
Posts: 71

My guess is that the '/' after '9' is terminating the regular expression. I think you meant to use a '\'.
I agree. Here's the link:
subject: Javascript validation in PHP
It's not a secret anymore!