Hai,
here i am using some function to validate special characters like single quotes given in input.
it is not working.please help me .But it is working fine when i put every thing in one function.
here code is given below
my Java Script file is
testscript.JS
function validate(formObject) {
if(specialCharacters(formObject.field_1))
{
alert("some special character are there which does not accept as input"
form.textObject.focus();
return false;
}
return true;
}
function specialCharacters(textObject) {
var objectValue = textObject.value;
var objectLength = objectValue.length;
var extraChars="#+/-.,?$&*():~`\;_ <>=";
var search;
for(var i = 0; i != objectLength; i++) {
aChar = objectValue.substring(i,i+1);
aChar = aChar.toUpperCase();
search = extraChars.indexOf(aChar);
if(search == -1 && (aChar < "A" || aChar > "Z" && (aChar < "0" || aChar > "9")
return true;
else
return false;
}
}
and my page is
<html>
<head>
<title>Test Page</title>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="testscript.JS"></SCRIPT>
</head>
<body>
<form action="test.jsp" name="test" method="post" onsubmit="return validate(this)">
field_1:<input name ="field_1" size="30" maxlength="30">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
thank u in advance
here i am using some function to validate special characters like single quotes given in input.
it is not working.please help me .But it is working fine when i put every thing in one function.
here code is given below
my Java Script file is
testscript.JS
function validate(formObject) {
if(specialCharacters(formObject.field_1))
{
alert("some special character are there which does not accept as input"
form.textObject.focus();
return false;
}
return true;
}
function specialCharacters(textObject) {
var objectValue = textObject.value;
var objectLength = objectValue.length;
var extraChars="#+/-.,?$&*():~`\;_ <>=";
var search;
for(var i = 0; i != objectLength; i++) {
aChar = objectValue.substring(i,i+1);
aChar = aChar.toUpperCase();
search = extraChars.indexOf(aChar);
if(search == -1 && (aChar < "A" || aChar > "Z" && (aChar < "0" || aChar > "9")
return true;
else
return false;
}
}
and my page is
<html>
<head>
<title>Test Page</title>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="testscript.JS"></SCRIPT>
</head>
<body>
<form action="test.jsp" name="test" method="post" onsubmit="return validate(this)">
field_1:<input name ="field_1" size="30" maxlength="30">
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
thank u in advance