Connecting Tech Pros Worldwide Help | Site Map

Need to throw an alert when enetering special characters in JavaScript

Newbie
 
Join Date: Sep 2009
Posts: 19
#1: Oct 4 '09
I need to throw an alert saying "Enetered special characters " alert when i click on submit button in javascript. Need code for this

Please help!!!!!
Newbie
 
Join Date: Sep 2009
Posts: 19
#2: Oct 4 '09

re: Need to throw an alert when enetering special characters in JavaScript


i used the below code. But it is not working. Please help as i need to finish it off.

Expand|Select|Wrap|Line Numbers
  1. if(validate(document.loginForm))
  2. {
  3. username=document.loginForm.value;
  4. document.loginForm.value=username;
  5. if (username.indexOf("%") != -1) {
  6. alert ("The box has special characters. \nThese are not allowed.\n");
  7. }
  8. passwd=document.loginForm.passwd.value;
  9. document.loginForm.passwd.value=passwd;
  10. document.loginForm.action="login.do";
  11. document.loginForm.submit();
  12. }
  13. }
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#3: Oct 4 '09

re: Need to throw an alert when enetering special characters in JavaScript


the code snippet does not make much sense
- there’s an unopened code block (closing curly bracket)
- there’s an undefined function (validate())
- there’s no definition of "special character"
- lines 4/8/9 seem unnecessary
Newbie
 
Join Date: Sep 2009
Posts: 19
#4: Oct 4 '09

re: Need to throw an alert when enetering special characters in JavaScript


I didn't post entire code. I have a text box called username.
If user is enetering sepecial character like % it should throw an alert.
This is my requirement.

Appreciate your help !!!!!!
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#5: Oct 4 '09

re: Need to throw an alert when enetering special characters in JavaScript


ok, test #1: do you actually enter this code block?
Newbie
 
Join Date: Sep 2009
Posts: 19
#6: Oct 5 '09

re: Need to throw an alert when enetering special characters in JavaScript


Hey iam able to do this.
Thanks for the response...!
Reply