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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Client side validation

    Hello all,
    I have spent the better part of the morning trying to write a entry field form validation. I want the user to be able to enter a-z (upper/lower fine), underscore, 0-9, spaces and nothing else.

    Can someone help?

    Thanks,
    Gsanbrook

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Here you go should do the trick.

    Code:
    <html>
    <head>
    <script>
    function formValid(frm)
    {
            var chk=frm.value.search(/[^A-Za-z0-9_\s]/); //allow only A-Z,a-z,_ & 0-9 space
            if(chk==-1)
    	{
    		alert('OK')
    	}
    	else
    	{
    		alert('No Good');
    	}
    }
    </script>
    </head>
    <body>
    <form>
    	<input type="text" onblur="formValid(this);">
    </form>
    </body>
    </html>
    Basscyst

    Edit: Oops still learning this, should work better now.
    Last edited by Basscyst; 07-12-2004 at 07:36 PM.
    Helping to build a bigger box. - Adam Matthews

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or, for a less interrupted user experience, this:
    Code:
    <html>
    <head>
      <script type="text/javascript">
        function allowWordChars (field) {
          if (field.value.match(/\W/)) {
            return false;
          }
          return true;
        }
      </script>
    </head>
    <body>
      <form>
       <input type="text" onkeydown="return allowWordChars(this);" />
      </form>
    </html>
    edit: missing parin
    Last edited by Choopernickel; 07-15-2004 at 04:38 PM.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Or for those whom need their hand held.......

    Code:
    <input type="text" 
    onkeyup="if(!this.value.charAt(this.value.length-1).match(/\w|_|\s/gi)){
    alert('illegal character');this.value=this.value.substring(0,this.value.length-1)}">
    .....Willy

  • #5
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the Help

    Thanks to all above, problem resolved.


  •  

    Posting Permissions

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