欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

限制输入框中的手机号码格式

最编程 2024-04-23 11:51:16
...

对手机号进行限制

下面代码是,限制输入的内容为纯数字,输入其他内容时会无法输入 在input中,再加上maxlength="11"即可完成对手机号的限制,要注意type="text"才生效

@keyup.native="searchForm.customerPhone=(searchForm.customerPhone).replace(/[^\d.]/g,'')"

对空格进行禁止输入 @keyup.native="editbatchData.name = editbatchData.name.replace(/\s+/g, '') " 下面代码是在element-ui表单中,对输入框进行的rules限制

export default {
data() { 
var customerPhone = (rule, value, callback) => { 
if (!value) 
{ return callback(new Error('手机号不能为空')); 
} else { const reg = /^1[3|4|5|7|8][0-9]\d{8}$/ console.log(reg.test(value)); 
if (reg.test(value)) 
{ callback(); }
else { 
return callback(new Error('请输入正确的手机号')); } } }; 
return { ruleForm: { phone: '' }, 
rules: { phone: [ {validator: customerPhone, trigger: 'blur'} ] } }; } }

推荐阅读