我想使用這裏找到的正則表達式來驗證表單http://regexlib.com/。我想要做的是過濾除a-z,逗號和撇號之外的所有字符。如果我使用此代碼:在正則表達式中逃避撇號?
<cfinput name="FirstName" type="text" class="fieldwidth" maxlength="90" required="yes" validateat="onsubmit,onserver" message="Please ensure you give your First Name and it does not contain any special characters except hyphens or apostrophes." validate="regular_expression" pattern="^([a-zA-Z'-]+)$" />
我收到以下錯誤:在表達式中不匹配[]。我想通了,這涉及到撇號,因爲它的工作原理,如果我使用此代碼(但不允許撇號):
<cfinput name="FirstName" type="text" class="fieldwidth" maxlength="90" required="yes" validateat="onsubmit,onserver" message="Please ensure you give your First Name and it does not contain any special characters except hyphens or apostrophes." validate="regular_expression" pattern="^([a-zA-Z-]+)$" />
所以我不知道是否有使用正則表達式時逃脫撇一些特殊的方法?
編輯
我想我找到了問題的根源所在所引起(感謝薩那託斯),不知道如何解決它。基本上CF正在生成隱藏字段驗證的字段如下:
<input type='hidden' name='FirstName_CFFORMREGEX' value='^([a-zA-Z'-]+)$'>
因爲它使用單撇號,而不是語音馬克輪值,則解釋撇號作爲值的末尾。
撇號是一個特殊字符,需要用前綴從標準文本逃脫「 \',try pattern =「^([a-zA-Z \' - ] +)$」HTH – John
@John Are you sure?它意味着什麼?它是如何用於正則表達式的「語言」? – xanatos
我說'嘗試',所以我不知道,正則表達式有很多口味,替換標記的表達式實際上是從我的Word 2002程序中不存在。 – John