Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    358
    Thanks
    2
    Thanked 0 Times in 0 Posts

    I want to do some validation for speacial character...

    I want to validate data input when user try to input special characters like "@#$%%^&*() ... and those characters like Ú, Ŕ, Ó...

    can i use this method?
    Code:
     str = str.toLowerCase();
      var strOk = ' -abcdefghijklmnopqrstuvwxyz0123456789';
      for ( var i = 0; i < str.length; i++ )
        if ( strOk.indexOf(str.charAt(i)) < 0 )
            return false;
    	return true;
    Any idea for this?
    Thanks.
    =====================================================
    From NinjaTurtle
    ++http://ohmygoh.blogspot.com|http://technology.ohmygoh.com++

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    using RegExp might be probably the easiest way. Probably it would be more hopeful if you would say which characters may pass.

    Well, for the begining, considering that you want to pass only numbers and letters, try this:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
    <
    html>
    <
    head>
    <
    title>Untitled Document</title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <
    meta http-equiv="Content-Style-Type" content="text/css">
    <
    meta http-equiv="Content-Script-Type" content="text/javascript">
    <
    script language="JavaScript" type="text/JavaScript">
    function 
    valid(field) {
            var 
    re = /^[0-9-A-z]*$/;
            if (!
    re.test(field.value)) {
                
    alert('Value must be only numbers or letters!');
                
    field.value field.value.replace(/[^0-9-A-z]/g,"");
            }
        }
    </script>
    </head>
    <body>
    <textarea name="text" cols="" rows="" onkeyup="valid(this)"></textarea>
    </body>
    </html> 
    You may add later which other characters u wanna pass, if needed
    Last edited by Kor; 03-17-2005 at 06:07 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •