nuke-normal-input
Version:
输入框
23 lines (21 loc) • 748 B
JavaScript
/**
* @param {dom node} element
* check whether the dom node's input is valid [ work in h5]
* number键盘输入非合法的时候value为空,此时需要校验是否合法。
* relative issue https://github.com/angular/angular.js/issues/2144
*/
exports.isValidInput = function (element) {
if (element.validity && !element.validity.valid) {
// if html5 validation says it's bad: it's bad
return false;
}
// Fallback to browsers that don't yet support html5 input validation
// Or we maybe want to perform additional validations
const value = element.value;
if (value != null) return true;
return false;
};
exports.isValidNumber = function (value) {
const reg = /^[-+]?[0-9]*\.?[0-9]+$/;
return reg.test(value);
};