Main keywords Case 1: Hangzhou, Zhejiang, Wenzhou
Main keyword Scenario 2: Zhejiang | Jiangsu | Shanghai, but spaces and | cannot be used in combination, that is, situations 1 and 2 cannot be mixed.
"Or" keywords: Education | Middle School | Primary School
Keywords: Principal-Professor-University
In addition, the number of primary keywords + or keywords cannot exceed 10
Unlimited number of non-keywords
Original article, reproduced Please note: http://www.cnblogs.com/phpgcs/
2 // main keyword validate 1 // user can input words with backspace or | splited 0 $. validator. addMethod ("kw_main_validate", function (value, element) {1 var kwmain =/^ ([\ u4e00-\ u9fa5a-zA-Z0-9] {} \ s ?) {} $ | ^ ([\ U4e00-\ u9fa5a-zA-Z0-9] {} \ | ?) {1, 10} $/; 2 // full match, use ^ and $3 return kwmain. test (value); 4}) 5 // or keyword validate 6 // user can input words with | splited 7 $. validator. addMethod ("kw_or_validate", function (value, element) {8 var kwmain =/^ ([\ u4e00-\ u9fa5a-zA-Z0-9] {} \ | ?) {1, 10} $/; 9 return kwmain. test (value); 10}) 11 // not keyword validate 12 // user can input words with-splited 13 $. validator. addMethod ("kw_not_validate", function (value, element) {14 var kwmain =/^ ([\ u4e00-\ u9fa5a-zA-Z0-9 }\-?) {1, 10} $/; 15 return kwmain. test (value); 16}) 17 // main kw + or kw <= 10 18 $. validator. addMethod ("checkMax10", function (value, element) {19 var main_string = $ ('# keyword_main '). val (); 20 var or_string = $ ('# keyword_or '). val (); 21 var main_num = main_string.split (/[\ s \ |]/). length; 22 var or_num = or_string.split (/[\ s \ |]/). length; 23 return (main_num + or_num-10)> 0 )? False: true; 24}) 1 rules: {5 keyword_main: {6 required: true, 7 kw_main_validate: true, 8 checkMax10: true 9}, 13 keyword_or: {14 kw_or_validate: true, 15 checkMax10: true 16}, 17 keyword_not: {18 kw_not_validate: true 19}, 20}, 21 messages: {14 keyword_main: {13 required: "Enter keywords ", 12 kw_main_validate: "Please check that the entered keywords are separated by spaces or" | "and cannot be mixed.", 11 checkMax10: "the total number of primary keywords and or keywords cannot exceed 10" 10 }, 9 keyword_or: {8 kw_or_validate: "The input keywords are separated by" | ". 7 checkMax10:" the total number of primary keywords and or keywords cannot exceed 10 "6}, 5 keyword_not: {4 kw_not_validate: "input keywords are separated by"-"." 3}, 2 },
^ Abc $
An online Regular Expression tool: http://tool.chinaz.com/regex,full matching is required.
Reference: http://topmanopensource.iteye.com/blog/568593