Before sending a form, how can I check if only spaces were entered (ragardless of how many there are)? That way I can prevent the form from sending. Any other character is ok as long as it's not just all spaces.
im not sure of with regex but this function should work: function isAllSpaces(strTxt) { for(i=0; i<strTxt.length; i++) if(strTxt.substr(i,1)!=" ") return false; return true; } Code (markup):
Hi, You can test input like: /^\s+$/.test(input_string) Code (markup): Regards Edit: And this will test both for empty strings and spaces only strings /^\s*$/.test(input_string) Code (markup):