Hi, I’m trying to validate a field for numbers only. I’ve been trying the following script but it doesn’t work.
<script type="text/javascript">
$(document).ready(function () {
$('#saveBtn').click(function () {
var trial = $('#HomeworkGrade').val();
var numbers = /^[0-9]+$/;
if (trial.value.search(numbers)==-1) {
alert('Correct data is entered')
$('#HomeworkGrade').css('background-color', '#fccaf9');
$("#HomeworkGrade").focus();
return false;
}
});
});
</script>
Also tried this: if (trial.value.match(numbers)).
Can you please help me to get this working? I appreciate any ideas in the right direction...thanks.