<script>
$(document).ready(function () {
//validation for Name field
$(".nameValidation").keypress(function(event){
var inputValue = event.which;
// allow letters and whitespaces only.
if(!(inputValue >= 65 && inputValue <= 122) && (inputValue != 32 && inputValue != 0)) {
swal("Warning", "Please enter only alphabet characters", "warning");
}
});
//can paste only alphabet
var alphaOnlyInput = document.getElementsByClassName('nameValidation');
var numofnameValidation = alphaOnlyInput.length;
alphaOnlyPattern = new RegExp('^[a-zA-Z ]+$');
let previousValue = '';
for (var i = 0; i < numofnameValidation; i++) {
var data=alphaOnlyInput[i];
data.addEventListener('input', (e) => {
let currentValue = data.value;
if (e.inputType.includes('delete') || alphaOnlyPattern.test(currentValue)) {
previousValue = currentValue;
}
data.value = previousValue;
});
}
//in name input alphabet validation
});
</script>
0 comments:
Post a Comment