Hi,

Why this code doesn't work? All I want to do is removing all the white spaces.


JavaScript

function validateForm(){
var postcode1 = (document.form1.textPostcode1.value).replace(/^\s*|\s*$/g, "");

if (postcode1 == "") {
alert ("ERROR");
} else {
alert ("CORRECT");
}
}

HTML

<form name="form1" action="save.php" method="POST" onSubmit="return validateForm()">
POSTCODE: <input type="text" name="textPostcode1" size="5" maxlength="4" />
<input type="submit" name="submitButton" value="Submit">
</form>

Thanks

You forgot the grouping parens

somestring.replace(/(^\s*|\s*$)/g, "")

solved. thanks chanwn

var postcode1 = (document.form1.textPostcode1.value).replace(/ /gi, "");