By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

If any illegal char exist do.. script help

P: 1
Hello everyone! My name is Veselin and i'm php and mysql coder. But now i have big problems with one javascript that i want to create (maybe because i don't understand nothing from javascript :)). I want to create validate form that search for illegal chars. "." "/" "_" "\" ","

My form name: MyJavaScriptForm
Field that i want to check: MyField


I'm made this..

Expand|Select|Wrap|Line Numbers
  1. function check(){
  2.  
  3.  
  4.  
  5.        if ( i don't know what ){
  6.        alert('There are illegals!');
  7.  
  8.        document.MyJavaScriptForm.MyField.focus();
  9.     return false;
  10.     }
  11.  
  12.  
  13.  
  14. document.MyJavaScriptForm.submit();
  15.  
  16. }

Can you help me please? Thank you!
Jul 2 '08 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Maybe you could just check for valid characters instead, but that really depends. If you only want alphanumeric characters, it's better to check against that instead of checking for every illegal character. However, if you want to allow any character except those that you've listed, then it makes more sense to check for those instead.

Now, how do we validate? The first thing to do is to get the input field value. Then you can use regular expressions to check the value. See these links:
http://developer.mozilla.org/en/docs...ar_Expressions
http://www.regular-expressions.info/javascript.html
http://www.w3schools.com/jsref/jsref_obj_regexp.asp
Jul 2 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.