Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

正则判断手机号,qq,颜色,邮箱 #49

Open
Sunny-117 opened this issue Nov 3, 2022 · 2 comments
Open

正则判断手机号,qq,颜色,邮箱 #49

Sunny-117 opened this issue Nov 3, 2022 · 2 comments

Comments

@Sunny-117
Copy link
Owner

// 手机号
let reg1 = /^1[44578]\d{9}$/g;
let str1 = '15928229999'
console.log(reg1.test(str1));
// qq号
let reg2 = /^[1-9][0-9]{4,9}$/g;
let str2 = '159222'
console.log(reg2.test(str2));

// 颜色
let reg3 = /#?([0-9a-fA-F]{6}|[0-9a-fA-F]{3})/g;
let str3 = '#abc'
console.log(reg3.test(str3));
// 邮箱
let reg4 = /^([A-za-z0-9_\-\.]+)+@([A-za-z0-9_\-\.]+)\.([A-Za-z]{2, 6})$/g;//+一到多
var reg = /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
let str4 = 'a11bc@didi.com'
console.log(reg4.test(str4));

@kangkang123269
Copy link

  1. 判断手机
const isPhoneNumber = (number) => {
  const regex = /^1[3456789]\d{9}$/;
  return regex.test(number);
}

console.log(isPhoneNumber('13912345678')); // true
console.log(isPhoneNumber('12345678901')); // false
  1. 判断QQ
const isQQNumber = (number) => {
  const regex = /^[1-9][0-9]{4,}$/;
  return regex.test(number);
}

console.log(isQQNumber('12345')); // false
console.log(isQQNumber('123456')); // true
  1. 判断颜色
const isColorCode = (color) => {
  const regex = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/;
  return regex.test(color);
}

console.log(isColorCode('#123')); // true
console.log(isColorCode('#aabbcc')); // true
console.log(isColorCode('#ffffff')); // true
console.log(isColorCode('#0000000')); // false
  1. 判断邮箱
const isEmail = (email) => {
  const regex = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  return regex.test(email);
}

console.log(isEmail('example@mail.com')); // true
console.log(isEmail('example@mail.com.cn')); // true
console.log(isEmail('example@mail')); // false

@veneno-o
Copy link
Contributor

// 手机
const reg1 = /^1[3-9]\d{9}$/g;

// qq
const reg2 = /^[1-9]\d{4,}$/g;

// 颜色
const reg3 = /^#([a-fA-F0-9]{3}|([a-fA-F0-9]{6}))$/g;

// email
const reg4 = /^[\w-]+@[\w-]+(\.[\w-]+)+$/g;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants