fix: 添加验证电话号码是否合法
This commit is contained in:
@@ -504,6 +504,7 @@ const cn = {
|
||||
number: '必须是数字',
|
||||
email: '不合法的E-mail地址',
|
||||
tel: '不合法的电话号码',
|
||||
telephone: '电话号码不能为空',
|
||||
host: '不合法的IP',
|
||||
fileSize: '文件过大',
|
||||
port: '不合法的端口',
|
||||
|
||||
@@ -515,6 +515,7 @@ const en = {
|
||||
positiveInteger: 'Positive integer',
|
||||
email: 'Invalid email', // '不合法的E-mail地址'
|
||||
tel: 'Invalid phone number', // '不合法的电话号码'
|
||||
telephone: 'Phone number cannot be empty',
|
||||
host: 'Invalid Host', // '不合法的Host'
|
||||
domain: 'Invalid domain',
|
||||
usize: 'Must be number(1 - 47)',
|
||||
|
||||
@@ -81,7 +81,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { host, port } from '@/components/common/js/validate'
|
||||
// import { host, port } from '@/components/common/js/validate'
|
||||
import {isvalidPhone} from "../../../../store/validate";
|
||||
|
||||
export default {
|
||||
name: 'userBox',
|
||||
components: {
|
||||
@@ -108,7 +110,16 @@ export default {
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
};
|
||||
const phoneVerification = (rule, value,callback) => {
|
||||
if (!value){
|
||||
callback(new Error(this.$t('validate.telephone')))
|
||||
}else if (!isvalidPhone(value)){
|
||||
callback(new Error(this.$t('validate.tel')))
|
||||
}else {
|
||||
callback()
|
||||
}
|
||||
};
|
||||
return {
|
||||
editUser: {},
|
||||
url: 'sys/user',
|
||||
@@ -132,6 +143,10 @@ export default {
|
||||
],
|
||||
email: [
|
||||
{ type: 'email', message: this.$t('validate.email') }
|
||||
],
|
||||
mobile: [
|
||||
{ validator: phoneVerification, required : true, trigger: 'blur' },
|
||||
{ required: true, message: '', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
rules2: { // 表单校验规则
|
||||
|
||||
@@ -65,6 +65,8 @@
|
||||
<script>
|
||||
import latlngPicker from '../latlngPicker'
|
||||
const regNum = /^[0-9]+.?[0-9]*/
|
||||
import {isvalidPhone} from "../../../store/validate";
|
||||
|
||||
export default {
|
||||
name: 'dcBox',
|
||||
components: { latlngPicker },
|
||||
@@ -75,6 +77,15 @@ export default {
|
||||
userData: Array
|
||||
},
|
||||
data () {
|
||||
const phoneVerification = (rule, value,callback) => {
|
||||
if (!value){
|
||||
callback(new Error(this.$t('validate.telephone')))
|
||||
}else if (!isvalidPhone(value)){
|
||||
callback(new Error(this.$t('validate.tel')))
|
||||
}else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
return {
|
||||
editDc: {},
|
||||
rules: {
|
||||
@@ -83,6 +94,10 @@ export default {
|
||||
],
|
||||
state: [
|
||||
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
||||
],
|
||||
tel: [
|
||||
{ validator: phoneVerification, required: true, trigger: 'blur' },
|
||||
{ required: true, message: '', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
areaData: [],
|
||||
|
||||
4
nezha-fronted/src/store/validate.js
Normal file
4
nezha-fronted/src/store/validate.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export function isvalidPhone(str) {
|
||||
const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
|
||||
return reg.test(str)
|
||||
}
|
||||
Reference in New Issue
Block a user