|
@@ -58,10 +58,10 @@ export function validAlphabets(str) {
|
|
|
* @param {string} email
|
|
|
* @returns {Boolean}
|
|
|
*/
|
|
|
-export function validEmail(email) {
|
|
|
- const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
|
- return reg.test(email)
|
|
|
-}
|
|
|
+// export function validEmail(email) {
|
|
|
+// const reg = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
|
+// return reg.test(email)
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* @param {string} str
|
|
@@ -153,3 +153,78 @@ export function validAdress(rule, value, cb) {
|
|
|
cb()
|
|
|
}
|
|
|
}
|
|
|
+/**
|
|
|
+ * 邮箱
|
|
|
+ * @param {*} s
|
|
|
+ */
|
|
|
+export function isEmail(s) {
|
|
|
+ // return /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
|
|
|
+ return /^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$/.test(s)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 手机号码
|
|
|
+ * @param {*} s
|
|
|
+ */
|
|
|
+export function isMobile(s) {
|
|
|
+ return /^[1][3|4|5|7|8|9][0-9]{9}$/.test(s)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 电话号码
|
|
|
+ * @param {*} s
|
|
|
+ */
|
|
|
+export function isPhone(s) {
|
|
|
+ // return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
|
|
|
+ return /^((0\d{2,3}(-)?\d{7,8})|(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8})$/.test(s)
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 汉字
|
|
|
+ * @param {*} s
|
|
|
+ */
|
|
|
+export function isZhcn(s, m, n) {
|
|
|
+ var re = new RegExp('^[\u2E80-\u9FFF]{' + m + ',' + n + '}$', 'gim')
|
|
|
+ return re.test(s)
|
|
|
+}
|
|
|
+
|
|
|
+/**********以下为公共验证方法***********/
|
|
|
+export function validEmail(rule, value, cb) {
|
|
|
+ if (value) {
|
|
|
+ if (!isEmail(value)) {
|
|
|
+ cb(new Error('邮箱格式错误'))
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function validMobile(rule, value, cb) {
|
|
|
+ if (value) {
|
|
|
+ if (!isMobile(value)) {
|
|
|
+ cb(new Error('请输入正确的手机号'))
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function validPhone(rule, value, cb) {
|
|
|
+ if (!isPhone(value)) {
|
|
|
+ cb(new Error('固定电话号码格式错误,格式如xxx-xxxxxxxx'))
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export function validZhcn(rule, value, cb) {
|
|
|
+ if (!isZhcn(value, 1, 25)) {
|
|
|
+ cb(new Error('仅可输入汉字'))
|
|
|
+ } else {
|
|
|
+ cb()
|
|
|
+ }
|
|
|
+}
|