Results 1 to 9 of 9

Thread: Need help on White space

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101

    Need help on White space

    i am creating a web page that allows visitors to enter information in text boxes and i want to be able to perform a check to see if the information enetered into the text boxes is only numbers and no white spaces(blank spaces) but i have no idea on how to go around doing this! can someone help me out? im a newbie to all this! thanks!

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Code:
    <html>
    <head>
    
    <script language="JavaScript1.2"><!--
    function regular(string) {
        if (string.search(/^[0-9]*$/) != -1)
             return true;
         else
             return false;
    }
    //--></script>
    </head>
    <body>
    <form>
    <input type="text" onChange="if (!regular(this.value)) alert('Not Valid')">
    </form>
    </body>
    </html>
    Mark
    -------------------

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    thanks mark!

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101

    Re:help please

    sorry to do this mark but i was wondering if i could return the focus to the textbox with the error in it!

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Have you got several textboxes then?

    Are you submitting the form somewhere?
    Mark
    -------------------

  6. #6
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    this might help:

    Code:
    <html>
    <head>
    
    <script language="JavaScript1.2"><!--
    function regular(string) {
        if (string.search(/^[0-9]*$/) != -1)
             return true;
         else
             return false;
    }
    
    function verify()
    {
    var j;
    
    for(j=0;j<document.frm1.txt1.length;j++)
    {
      if(!regular(document.frm1.txt1[j].value))
      {
    	alert('Not Valid');
    	document.frm1.txt1[j].focus();
    	return false
     }
    
    }
    return true;
    }
    //--></script>
    </head>
    <body>
    <form onSubmit='return verify()' name='frm1'>
    <input type="text" name="txt1"><br>
    <input type="text" name="txt1"><br>
    <input type="text" name="txt1"><br>
    <input type="text" name="txt1"><br>
    
    </form>
    </body>
    </html>
    Mark
    -------------------

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    oh sorry for the late reply mark! i want to check all the textboxes after they lose the focus! can i just insert the script you just posted in the tags by using onBlur? thanks

  8. #8
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Try this:

    Code:
    <html>
    <head>
    
    <script language="JavaScript1.2"><!--
    function regular(string) {
        if (string.search(/^[0-9]*$/) != -1)
             return true;
         else
             return false;
    }
    
    function verify(t)
    {
    
      if(!regular(t.value))
      {
    	alert('Not Valid');
    	t.focus();
    	return false
    }
    return true;
    }
    //--></script>
    </head>
    <body>
    <form>
    <input type="text" onBlur="verify(this)"><br>
    <input type="text" onBlur="verify(this)"><br>
    <input type="text" onBlur="verify(this)"><br>
    <input type="text" onBlur="verify(this)"><br>
    
    </form>
    </body>
    </html>
    Mark
    -------------------

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jun 2002
    Posts
    101
    it all works great mark but just 2 little flaws that i have just found: if i leave the textbox so that the value has absolutely no contents(length=0), it will not work!; and i want to be able to get rid of leading zeros, if possible. im sorry i didnt tell you this earlier but i just saw it now! sorry to be a pain! thanks for everything

Posting Permissions

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



Click Here to Expand Forum to Full Width