0

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

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by veledrom
0

solved. thanks chanwn

var postcode1 = (document.form1.textPostcode1.value).replace(/ /gi, "");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.