2012-04-02 16 views
0

我需要在我的TextArea的驗證,所以我的TextArea不包含特定的特殊字符,如「|」只。在textarea驗證,所以它不包含特定的特殊字符與Jquery

我是想這樣的事情:

$('#CustomButton').click(function() { 
if $("#CustomQuestionText").val()).indexOf('|') > -1) 
{ 
alert("The box has special characters. \nThese are not allowed.\n"); 
} 
else 
{ 
my code here.. 
} 

任何解決方案表示讚賞。

在此先感謝

+0

你有你'if'聲明錯字,是故意的嗎? – 2012-04-02 09:58:45

回答

1

試試這個

$('#CustomButton').click(function() { 
    if($("#CustomQuestionText").val().search('|')>=0){ 
    { 
    alert("The box has special characters. \nThese are not allowed.\n"); 
    } 
    else 
    { 
    my code here.. 
    } 
}); 
+0

如果我想在按鍵上做到這一點,它會是什麼樣子? – Obsivus 2012-04-02 10:29:13

+0

檢查編輯的帖子 – 2012-04-02 11:37:59