Skip to content

Instantly share code, notes, and snippets.

@QETHAN
Created November 2, 2017 06:14
Show Gist options
  • Save QETHAN/f0c3f40361b4b01cb42f4c5cce9610d7 to your computer and use it in GitHub Desktop.
Save QETHAN/f0c3f40361b4b01cb42f4c5cce9610d7 to your computer and use it in GitHub Desktop.
const checkIp = (rule, value, callback) => {
if (!value) {
return callback(new Error(`服务器IP不能为空`))
}
let regIp = /^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$/
let status = regIp.test(value)
if (!status) {
callback(new Error('IP格式错误'))
} else {
callback()
}
}
const checkBlank = (rule, value, callback) => {
if (!value) {
let field = rule.field === 'username' ? '用户名' : '密码'
return callback(new Error(`${field}不能为空`))
} else {
callback()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment