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

检验字符串首尾是否含有数字 #51

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

检验字符串首尾是否含有数字 #51

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

Comments

@Sunny-117
Copy link
Owner

let reg = /^\d|\d$/g;//或
let reg2 = /^\d[\s\S]*\d$/g;//都
@kangkang123269
Copy link

function hasNumberAtStartAndEnd(str) {
  // 检查字符串开头是否包含数字
  if (/\d/.test(str.charAt(0))) {
    return true;
  }
  
  // 检查字符串结尾是否包含数字
  if (/\d/.test(str.charAt(str.length - 1))) {
    return true;
  }
  
  // 如果字符串既不以数字开头也不以数字结尾,则返回false
  return false;
}

@veneno-o
Copy link
Contributor

/^((\d.*)|(.*\d))$/

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