123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- /**
- * Validate v1.0.0 通用验证
- * @description 项目中用到的表单验证规则
- */
- import test from '@/sheep/helper/test.js';
- import { t } from '@/locale'
- // 用户名
- export const username = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_username'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!value) {
- callback(t('rules.username_required'));
- }
- return true;
- },
- },
- ],
- };
- // 手机号
- export const mobile = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_phone'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!test.mobile(value)) {
- callback(t('rules.incorrect_phone_format'));
- }
- return true;
- },
- },
- ],
- };
- // 密码
- export const password = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_password'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]+\S{5,12}$/.test(value)) {
- callback(t('rules.password_requirements'));
- }
- return true;
- },
- },
- ],
- };
- // 短信验证码
- export const code = {
- rules: [
- {
- required: true,
- errorMessage:t('rules.enter_verification_code'),
- },
- ],
- };
- // 真实姓名
- export const realName = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_name'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!test.chinese(value)) {
- callback(t('rules.enter_chinese_characters'));
- }
- return true;
- },
- },
- ],
- };
- export const taxName = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_invoice_title'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!test.chinese(value)) {
- callback(t('rules.enter_chinese_characters'));
- }
- return true;
- },
- },
- ],
- };
- // 税号
- export const taxNo = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_tax_number'),
- },
- ],
- };
- // 开户行
- export const bankName = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_bank'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!test.chinese(value)) {
- callback(t('rules.enter_chinese_characters'));
- }
- return true;
- },
- },
- ],
- };
- // 银行卡号
- export const bankCode = {
- rules: [
- {
- required: true,
- errorMessage:t('rules.enter_bank_card_number'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- if (!/^\d+$/.test(value) ) {
- callback(t('rules.correct_bank_card_number'));
- }
- return true;
- },
- },
- ],
- };
- // 支付宝账号
- export const alipayAccount = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_alipay_account'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- let isEmail = test.email(value);
- let isMobile = test.mobile(value);
- if (!isEmail && !isMobile) {
- callback(t('rules.correct_account_number'));
- }
- return true;
- },
- },
- ],
- };
- // 支付宝账号
- export const email = {
- rules: [
- {
- required: true,
- errorMessage: t('rules.enter_email'),
- },
- {
- validateFunction: function (rule, value, data, callback) {
- let isEmail = test.email(value);
- if (!isEmail) {
- callback(t('rules.correct_email'));
- }
- return true;
- },
- },
- ],
- };
- export default {
- mobile,
- alipayAccount,
- bankCode,
- bankName,
- realName,
- password,
- code,
- taxNo,
- taxName,
- email
- };
|