|
-
Feb 26th, 2013, 05:51 PM
#1
Thread Starter
Member
Javascript, If input cointains characters not declared on a list show message
Hi, I need a script that shows a message If an input (html) contains characters that are not on the list. At the moment I have this script:
Code:
var iChars = "ABCDEFGHIJKLMNOPQRSTVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
for (var i = 0; i < document.formulario.usuario_nombre.value.length; i++) {
if (iChars.indexOf(document.formulario.usuario_nombre.value.charAt(i)) != -1) {
alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again.");
document.formulario.usuario_nombre.focus()
return false;
}
}
That script "reads" the input and if a character matches with the written in the "iChars" variable, it shows a message, okay i need the opposite.. If any character in the input doesn't match with "iChars", show a message.. Thanks !
-
Feb 26th, 2013, 06:05 PM
#2
Thread Starter
Member
Re: Javascript, If input cointains characters not declared on a list show message
Solved, just change the operator:
Code:
if (iChars.indexOf(document.formulario.usuario_nombre.value.charAt(i)) === -1) {
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
|
Click Here to Expand Forum to Full Width
|