首页 > 解决方案 > 正则表达式查找字符串是否仅包含特殊字符或数字和特殊字符的混合

问题描述

我需要在 js 中编写一个正则表达式来验证字符串是否只包含特殊字符以及特殊字符和数字的混合。

我的意思是它不应该接受这些

  1. 123(只有数字)
  2. 123@#@$12(两者混合)
  3. @#$​​@$(仅限特价)

它可以接受

  1. 123fgfdg
  2. @#$​​dfgdfg

请考虑其他语言日语和韩语

我有这个代码

function ValidateValue(str){
    if(trim(str).length == 0){
          getMessage(7); //if string is empty
     }if(/^[^a-zA-Z]+$/.test(str)){//check if the string contains special and digits 
          getMessage(21); //this part works fine for english but not for japanese or korean.
     }if(IsInteger(trim(str))){  
          getMessage(8);// if string contains only numbers
     }
}

标签: javascriptregexvalidation

解决方案


推荐阅读