互联网技术 · 2024年2月28日

QQ号、微信号的JavaScript正则表达式

^ 脱字符:匹配开头,若存在多行匹配多行的行头。$ 美元符:匹配尾部,若存在多行匹配多行的尾部。我们知道正则是一种匹配模式,要么匹配字符,要么匹配位置。

QQ正则

//QQ号正则,5至11位
var qqPattern = /^[1-9][0-9]{4,10}$/;
//输出 true
console.log(qqPattern.test(“65974040”));

微信号正则

//微信号正则,6至20位,以字母开头,字母,数字,减号,下划线
var wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
//输出 true
console.log(wxPattern.test(“RuilongMao”));

OpenMagic API

Need more than content? Move into the product flow.

If you are here for model access, pricing, developer docs, or the future API console, the dedicated product path now lives on api.openmagic.ai.