0

I am using jquery.validate.js plugin to validate a form and I want regex with match Titles(Books or Non-Books or any Title of products) but I failed to match and I wanted a regex which match following,

=> From 'A-Z' , 'a-z', whitespace, as well as tab space , special characters like ' ( ' , ' ) ' , - , _ , and 'coma' , dot , semicolon, ifen ,' : ', and all numbers

I used following regex for above:

  1. /^[a-zA-Z0-9.'\-_\s]$/
  2. /^[\d,\w,\s\;\:\()]$/
  3. /^[^.-_#][A-Za-z0-9_ -.]+$/ - this is showing error when Title starts from upper case 'A'

and I referred following sites

http://regexpal.com/ // in this site i checked the above characters bot it showed error on validate

http://regexlib.com/DisplayPatterns.aspx?AspxAutoDetectCookieSupport=1

http://www.vogella.com/articles/JavaRegularExpressions/article.html

thanks in advance

4

2 回答 2

4

这个正则表达式应该匹配你想要/^[A-Za-z0-9\s\-_,\.;:()]+$/的。特殊字符,如 . & - 需要用反斜杠转义。您还需要在方括号的末尾加上一个 + 或 * 来分别表示“一个或多个”或“任意数量”。

于 2013-07-18T10:37:53.180 回答
0

我想这个你想要DEMO

^\w++(?:[.,_:()\s-](?![.\s-])|\w++)*$

描述

^           # Start of string
\w++        # Match one or more alnum characters, possessively
(?:         # Match either
 [.,_:()\s-]  # a  "special" character
 (?![.\s-]) #  aserting that it's really single
|           # or
 \w++       # one or more alnum characters, possessively
)*          # zero or more times
$           # End of string
于 2013-07-18T10:37:16.563 回答