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 Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How To Validate Blanks, Spaces in Text Area

    I've the following code:

    Code:
    function validateText(fld, errMsg)
    {
    	if(fld.value=="" || fld.value == " ")
    	{
    		alert("Please enter a value for " + errMsg + ".");
    		fld.focus();
    		return false;	
    	}//endif
    	return true;
    }//endfunction validatetext
    However, it works only if there is a space, not when multiple spaces occur consecutively.

    How do I make this validate if the user purposely enter spaces/blanks?

  • #2
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another thing, I tried searching if someone else had posted this by using the following keywords: validate space blank null.

    No results. Maybe someone could kindly point me in the right direction if this question has been posted before.

  • #3
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try replacing: if(fld.value=="" || fld.value == " ")
    With: if(fld.value.length == 0 || fld.value.match(/^\s+$/))

    .....Willy
    Last edited by Willy Duitt; 08-26-2004 at 08:20 AM.

  • #4
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Willy!

    Though There's a missing ) in the last part.

  • #5
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ooops...


  •  

    Posting Permissions

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