js正則驗證表達式驗證


/* 合法uri */
export function validateURL(textval) {
  const urlregex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/? #[\]@!\$&'\*\+,;=.]+$/
  return urlregex.test(textval)
}
/*驗證中文*/
static bool isChinese(String value) {
return RegExp(
r"[\u4e00-\u9fa5]")
.hasMatch(value);
}
/* 小寫字母 */
export function validateLowerCase(str) {
  const reg = /^[a-z]+$/
  return reg.test(str)
}
/* 大寫字母 */
export function validateUpperCase(str) {
  const reg = /^[A-Z]+$/
  return reg.test(str)
}
/* 大小寫字母 */
export function validateAlphabets(str) {
  const reg = /^[A-Za-z]+$/
  return reg.test(str)
}
/* 匹配非負整數(正整數 + 0) */
export function validatestockWarn(str) {
  const reg = /^(0|[1-9][0-9]*)$/
  return reg.test(str)
}
/* 驗證特定網站 只驗證京東和蘇寧網站 */
export function validateCompareWebsite(str) {
  const reg = /^((https\:\/\/[0-9a-zA-Z\_]+\.|http\:\/\/[0-9a-zA-Z\_]+\.|https\:\/\/|http\:\/\/)|([0-9a-zA-Z\_]+\.){0,1})(jd|suning)\.(com$|com\/[\S]*)/i
  return reg.test(str)
}
/* 固定電話 */
export function validateTelephone(str) {
  const reg = /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/
  return reg.test(str)
}
/* 手機號碼 */
export function validatePhoneNumber(str) {
  const reg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/
  return reg.test(str)
}
/* 手機號碼和固定電話 */
export function validatePhTelNumber(str) {
  const reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/
  return reg.test(str)
}
/* 電子郵箱 */
export function validateEmail(str) {
  const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/
  return reg.test(str)
}
/* 郵編 */
export function validateZipCode(str) {
  const reg = /^[1-9][0-9]{5}$/
  return reg.test(str)
}
/* 身份證 */
export function validateIDCard(str) {
  const reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  return reg.test(str)
}
/* 銀行卡號 15位或者16位或者19位 */
export function validateBank(str) {
  const reg = /^([1-9]{1})(\d{14}|\d{18}|\d{15})$/
  return reg.test(str)
}
/* 納稅人識別碼 */
export function validateTaxpayer(str) {
  const reg = /^([1-9]{1})(\d{14}|\d{18}|\d{15})$/
  return reg.test(str)
}
/* 匹配全空格 */
export function validateAllBlank(str) {
  const reg = /^\s+$/gi
  return reg.test(str)
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM