|
Q373 How can I check that a text box entry is empty or has just spaces?
irt.org | Knowledge Base | JavaScript | Form 3.4 | Q373 [ previous next ]
Q373 How can I check that a text box entry is empty or has just spaces?
Try:
<SCRIPT LANGUAGE="JavaScript"><!--
function stripSpaces(x) {
while (x.substring(0,1) == ' ') x = x.substring(1);
return x;
}
function empty(x) { if (x.length > 0) return false; else return true; }
//--></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2"><!--
function stripSpaces(x) { return x.replace(/^\W+/,''); }
//--></SCRIPT>
<FORM NAME="myForm">
<INPUT TYPE="TEXT" NAME="myText">
<INPUT TYPE="BUTTON" VALUE="Test If Empty" onClick="if (empty(stripSpaces(this.form.myText.value))) alert('empty')">
</FORM>
|
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.