I recently learnt this code but this code is not working as it is expected to .It is for form validation
function username_validation(name){
var valid_name = /^[a-zA-Z0-9_]{5,30}$/;
if(!valid_name.test(name))
{
return false;
}
else
{
return true;
}
}
You must hook this function to an event listener.
Like :
So this function will be triggered every time that particular form is submitted.
There’s nothing wrong with your function.
The line :
creates a RegExp object.
Then :
checks if the
namemathces with thevalid_namepattern.RegExp has a boolean method
test(s)which returns true if the given stringsmatches with the RegExp patternA better way to write that would be :
Hope it helps…