Page 1 of 1

problem in validation script for whitespaces

Posted: Thu Nov 01, 2007 12:55 am
by djdon11
feyd | Please use

Code: Select all

,

Code: Select all

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 


Please help me soon

Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

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]

Re: problem in validation script for whitespaces

Posted: Wed Nov 14, 2007 6:46 pm
by rturner
djdon11 wrote:feyd | Please use

Code: Select all

,

Code: Select all

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 


Please help me soon

Thanks


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

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
[/syntax]

Posted: Tue Dec 04, 2007 11:57 pm
by devendra-m
\s is meant for white spaces in regular expression.


[^A-Za-z\s]