js match regular parity

1, the number of parity check the contents of the input box

Check box input, as long as the last digit is an even number 02468 can be determined

正则式为: ^\d*[02468]$

2, parity checking and remove the string

If you need to remove the parity, you need to check on the overall figures are, if only the check will only delete the last digit number to the end of

var str = 'a1s2d3f4g12';
var _str;
_str = str.replace(/\d*[02468]/g,''); 
console.log(_str ); //a1sd3fg
Published 27 original articles · won praise 21 · views 4598

Guess you like

Origin blog.csdn.net/weixin_43997143/article/details/105049303