Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check for blank spaces in a sentence without using regex.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 130
    Comment on it

    For this , we can use jQuery function named as split().Using split() function we can check easily that whether a input string have spaces or not.

    split function accepts first parameter a delimiter , second parameter is a string and split function splits the string into array by the given delimiter and returns string as same if in case there is no delimiter found.

    Here is the code you have to use for this -

    // id of the textbox is timeTaken
    var strText = $.trim($('#timeTaken').val());
    if(strText.split(' ').length > 1 )
    {
        console.log('no spaces please');
    }
    else
    {
        console.log('yep. correct.');
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: