Wednesday, 6 August 2014

How to remove spaces from a text input box


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://code.jquery.com/jquery.js" type="text/javascript"></script>
<script>
$(function () {
$("#btnSubmit").click(function () {
alert($("#txtName").val().length);
if ($("#txtName").val().replace(/\s+/g, '').length != 0) {
alert($("#txtName").val().replace(/\s+/g, ''));
alert($("#txtName").val().replace(/\s+/g, '').length);
}
else {
alert("No data");
}
});
});
</script>
</head>
<body>
<textarea name="txtName" id="txtName"></textarea>
<button id="btnSubmit">Submit</button>
</body>
</html>
view raw gistfile1.js hosted with ❤ by GitHub