Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 10745e6

Browse files
committed
feat: add mobile number split
1 parent 0de5fb6 commit 10745e6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎js/mobile_334.js‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* @Author: Chacha
3+
* @Date: 2022年05月03日 12:20:57
4+
* @Last Modified by: Chacha
5+
* @Last Modified time: 2022年05月03日 12:21:37
6+
*/
7+
8+
// 适合纯11位手机
9+
const splitMobile = (mobile, format = "-") => {
10+
return String(mobile).replace(/(?=(\d{4})+$)/g, format);
11+
};
12+
// 适合11位以内的分割
13+
const splitMobile2 = (mobile, format = "-") => {
14+
return String(mobile)
15+
.replace(/(?<=(\d{3}))/, format)
16+
.replace(/(?<=([\d\-]{8}))/, format);
17+
};
18+
19+
console.log(splitMobile(13798247501));
20+
console.log(splitMobile2(13798247501));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /