带通配符的最小字符数

时间:2016-02-13 15:26:50

标签: javascript jquery regex

我有以下外卡搜索,它会查找以下条件。

ALTER FUNCTION [dbo].[ShopCust] (@sID int)
RETURNS @tbl_Customers table (ShopID int, ShopName varchar(25), NbrCust int)
AS
BEGIN

INSERT INTO @tbl_Customers

SELECT  ShopID , ShopName, NbrCust
FROM dbo.ShopTbl                                        AS X
JOIN 
(
SELECT SupplierID , COUNT(*) AS NbrCust
FROM dbo.CustomerTbl
WHERE SupplierID = @sID 
)                                                       AS Y
ON X.ShopID = Y.SupplierID

RETURN
END
GO  
  1. 如果用户输入2个字符,则其有效
  2. 如果用户输入3个字符,则其有效
  3. 如何验证用户输入2个字符$.validator.addMethod("FirstName", function (value, element) { return this.optional(element) || /^[a-zA-Z''-'\s]{3,20}[\%\*]{0,1}$/i.test(value); }, "For wild card search minimum of 3 characters should be entered."); $("#frmJscsSearch").validate({ rules : { FirstName : "required FirstName" }, }); 然后无效?

1 个答案:

答案 0 :(得分:1)

看看这个正则表达式是否符合您的要求(想法是使用交替$counter = 0; foreach ($items as $item) { $counter++; //When counter is 2.. do something.. (1 or 2, can't remember, a while since i worked with php) if ($counter == 2) { continue; } //when gap is reached, reset counter, ( 5 or 6, can't remember..) if ($counter == 6) { $counter = 0; } } ):

|

你原来的正则表达式也有点乱,所以我编辑了它 您也可以尝试检查错误的输入而不是正确的输入:

/(^[a-z '\-]+$)|(^[a-z '-]{3,}[\%\*]$)/i

通过这种方式,您可以更轻松地检查更具体的条件。上面的正则表达式描述了以下规则:

  • 值应仅包含var re = /([^a-z '\-*%])|(^[\w\W]{0,2}[\*\%]&)|(^[ \-*%'])|([ \-]$)|([ \-']{2,})/i !(re.test(value)) 个字符;
  • a-z '-*%*应为最后一个符号(如果使用),前面至少有三个其他字符;
  • 值不能以%;
  • 开头
  • 值不能以-'*%;
  • 结尾
  • 值不能连续包含多个-