In the below Javascript code I am validating the dateformat in which backspace and delete key is not working.
function AcceptDateCharacters(event, separator) {
var keyCode = event.which ? event.which : event.keyCode;
if((separator.length != 1) && (keyCode > 8 && keyCode < 45))
{
return false;
}
//lets allow digits
var expression = "^[0-9";
//lets allow the separator character
expression += separator;
//lets complete the expression
expression += "]$";
var regex = new RegExp(expression);
return AcceptRegExOnly(event, regex)
// var keyCode = event.which ? event.which : event.keyCode;
//if ((keyCode >8 && keyCode <= 45))
return true;
};
Can't you just add an if statement for backspace and delete?
function AcceptDateCharacters(event, separator) {
var keyCode = event.which ? event.which : event.keyCode;
if((separator.length != 1) && (keyCode > 8 && keyCode < 45))
{
return false;
}
// added conditional
if(keyCode == 8 || keyCode == 46){
return true;
}
//lets allow digits
var expression = "^[0-9";
//lets allow the separator character
expression += separator;
//lets complete the expression
expression += "]$";
var regex = new RegExp(expression);
return AcceptRegExOnly(event, regex)
// var keyCode = event.which ? event.which : event.keyCode;
//if ((keyCode >8 && keyCode <= 45))
return true;
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.