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

常用的工具方法 #14

Open
alianzhang opened this issue Dec 13, 2019 · 3 comments
Open

常用的工具方法 #14

alianzhang opened this issue Dec 13, 2019 · 3 comments

Comments

@alianzhang
Copy link
Owner

alianzhang commented Dec 13, 2019

@alianzhang
Copy link
Owner Author

alianzhang commented Dec 13, 2019

let keyWord = ['习近平','王岐山'];
let str = '习近平总书记出席2018年全国政治委员委员会,王岐山总理发表重要讲话,旨在要坚持贯彻习近平总书记提出的社会主义核心价值观';
function seekKeyWord(key, s) {
  key.map(item => {
    let reg = new RegExp(item, 'gm'); // g、m分别代表全局global和多行multiline
    s = s.replace(reg, `<span class='key-word'>${item}</span>`)
  })
  document.body.innerHTML = s;
}
seekKeyWord(keyWord, str);

@alianzhang
Copy link
Owner Author

业务常用正则:

// 手机号正则
export const MOBILE = /^1\d{10}$/
// 座机号正则
export const PHONE = /^0\d{11}/
// 身份证正则
export const IDCARD = /(^\d{15}$)|(^\d{17}([0-9]|X|x)$)/
// 银行卡正则
export const BANKCARD = /^\d{13,19}$/
// 金额保留两位小数正则
export const AMOUNT = /((^[1-9]\d*)|^0)(.\d{1,2})?$/

@alianzhang
Copy link
Owner Author

alianzhang commented May 15, 2020

formatAmount (amount) {
      amount.split('').reverse().reduce((total, each, i) => {
        total.push(each)
        if ((i + 1) % 3 === 0) total.push('.')
        return total
      }, []).reverse().join('')
 }

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

1 participant