Home >Web Front-end >JS Tutorial >Introduction to the use of javascript practical small functions_javascript skills

Introduction to the use of javascript practical small functions_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:16:041091browse

1. Prevent the input of non-numbers, except for backspace

Copy code The code is as follows:



2. Limit the maximum input string length
Copy the code The code is as follows:

//Limit the maximum input length
var checkMaxL = function(length) {
var regC = /[^ - ~] /g;
var regE = /D /g;
var str = jQuery("#remark").val();

if (regC.test(str)){
jQuery("#remark").val(str.substring(0, length));
}

if(regE.test(str)){
jQuery("# remark").val(str.substring(0, length));
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn