-
Validation to allow numbers letters only (Regular Expression)
function usernameValidate(usernameString) {
var valid = true;
if ( usernameString == "" ) {
feedback('userMess','Enter your username here',7);
valid = false;
}
else if ( usernameString.length <= 5 ){
feedback('userMess','Username too short',7);
valid = false;
}
else if ( !validUsernameString(usernameString) ) {
feedback('userMess','Username contails illegal characters',7);
valid = false;
}
else feedback('userMess', '✔',1);
if ( valid ) return true;
else return false;
}
function validUsernameString(usernameString) {
// regular expression
var filter = /^[a-z]|[0-9]/;
if (filter.test(usernameString)) return true;
else return false;
}
Im pretty sure the regular expression used is incorrect. The field only requires the text box to allow only numbers and letters and no other characters. At the moment you are able to enter any character in the textbox and it says it is valid.
What would be the correct regular expression to use for this type of validation?
Regards
Akin
-
-
-
-
Cheers mate works now
Much appreciated
Akin
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks