<input type="text" name="zip" id="zip" />
<a href="#" id="test">click to test</a>
$(document).ready(function () {
function checkZip(value) {
return (/(^\d{5}$)|(^\d{5}-\d{4}$)/).test(value);
}
$('#test').on('click', function (e) {
e.preventDefault;
var value = $('#zip').val();
if (checkZip(value)) {
alert('valid zip');
} else {
alert('invalid zip');
}
});
});
<a href="#" id="test">click to test</a>
$(document).ready(function () {
function checkZip(value) {
return (/(^\d{5}$)|(^\d{5}-\d{4}$)/).test(value);
}
$('#test').on('click', function (e) {
e.preventDefault;
var value = $('#zip').val();
if (checkZip(value)) {
alert('valid zip');
} else {
alert('invalid zip');
}
});
});
No comments:
Post a Comment