and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello friends ..
i have a problem in my script
here is a snippet of javascript code which is for the checking of alphabetic fields only means only alphabates can be enter in the text fields .. but a problem is going on with this if user enters only alphabates then there should be no any error but users enters all the alphabates with white spaces then there is message coming only alphabtes are allowed , means this code is not considering white spaces as a alphabate so have a look on this code and give me idea what should i have to do for fixing my bug .............. here is the code : - >
[syntax="javascript"]
case "alphabetic":
case "alpha":
{
var charpos = objValue.value.search("[^A-Za-z]");
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alphabetic characters allowed\n No Whitespaces ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}//alpha
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hello friends ..
i have a problem in my script
here is a snippet of javascript code which is for the checking of alphabetic fields only means only alphabates can be enter in the text fields .. but a problem is going on with this if user enters only alphabates then there should be no any error but users enters all the alphabates with white spaces then there is message coming only alphabtes are allowed , means this code is not considering white spaces as a alphabate so have a look on this code and give me idea what should i have to do for fixing my bug .............. here is the code : - >
[syntax="javascript"]
case "alphabetic":
case "alpha":
{
var charpos = objValue.value.search("[^A-Za-z ]"); // <- see the space here....
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+": Only alphabetic characters allowed\n No Whitespaces ";
}//if
alert(strError + "\n [Error character position " + eval(charpos+1)+"]");
return false;
}//if
break;
}//alpha
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color][/quote]
Just add a space to allow whitespace. You may want to allow punctuation like comma and period too!
[syntax="javascript"]
var charpos = objValue.value.search("[^A-Za-z ]"); // <- see the space here