1. 第一种写法
is_orEnglishCharacter = function is_orEnglishCharacter(num) {
regex = /^[A-Za-z_]+$/;
return regex.test(num);
}
/**
* [checkInput 校验表单]
* @param {[type]} elementId [元素ID带#]
* @param {Function} functionName [校验方法]
* @param {[type]} message [提示信息]
* @return {[type]} none [none]
*/
function checkInput(elementId,functionName,message){
$(elementId).on('input propertychange', function(event) {
event.preventDefault();
var num = $(this).val();
var bool = functionName(num);
if (bool) {
...
}
});
}
checkInput('#symbolA',is_orEnglishCharacter);
2. 第二种写法,传入的方法和参数分开
function is_orEnglishCharacter(num) {
regex = /^[A-Za-z_]+$/;
return regex.test(num);
}
/**
* [checkInput 校验表单]
* @param {[type]} elementId [元素ID带#]
* @param {type} num [引入函数的参数]
* @param {Function} functionName [校验方法]
* @param {[type]} message [提示信息]
* @return {[type]} none [none]
*/
function checkInput(elementId,num,functionName,message){
$(elementId).on('input propertychange', function(event) {
event.preventDefault();
var num = $(this).val();
var bool = functionName(num);
if (bool) {
...
}
});
}
checkInput('#symbolA',this.value,is_orEnglishCharacter);