Okay, I know how to check if fields are null and stuff but how do I check to see if fields have no characters in them for example if I do this. Javascript Code: if(var === null || var === "" || var.length === 0) { return false } else { //code here } Code (markup): This only checks for certain types of emptyness. How do I check to make sure that the user inputed at least one character other than the 'space key'? Thanks. ~imzoeb
Try this code: if(var === null || var.replace(/[\s]/g,"").length===0) { return false } else { //code here } Code (markup):
Okay. Here is the script that doesn't work. Javascript Code: //get text inputtext = ""; inputtext = "text=" + document.getElementById('inputbox').value; //validate if(inputtext === null || inputtext.replace(/[\s]/g,"").length===0) { } else { //send text param = inputtext; xmlhttpsend.open("POST../../inputfunction.php",true); xmlhttpsend.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttpsend.setRequestHeader("Content-length", param.length); xmlhttpsend.setRequestHeader("Connection", "close"); xmlhttpsend.send(param); } Code (markup): Thanks. ~imozeb
I have 2 questions 1. What doesn't work? 2. How can inputtext has no char if "inputtext = "text=" + document.getElementById('inputbox').value;"?
1. If the user just imputs spaces into the text field instead of letters, numbers, and symbols it still sends the value. (This results in the output box having a line of blank text. I want to only send the text if the user imputs letter or numbers or symbols with or without spaces.) 2. inputtext can have no chars because the user can (if they are evil) imput just spaces instead of letters, numbers, and symbols, which would result in document.getElementById('inputbox').value = " " (a few spaces). Thanks.
Do it by this method: //get text inputboxvalue = document.getElementById('inputbox').value; //validate if(inputboxvalue === null || inputboxvalue.replace(/[\s]/g,"").length===0) { } else { //send text inputtext = "text=" + inputboxvalue; param = inputtext; xmlhttpsend.open("POST../../inputfunction.php",true); xmlhttpsend.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttpsend.setRequestHeader("Content-length", param.length); xmlhttpsend.setRequestHeader("Connection", "close"); xmlhttpsend.send(param); } Code (markup):