2017-02-04 5 views
0

ここに表示されたリストから、私たちの要件を満たす例は見つかりませんでした。jQueryを使用してGridviewで電子メールアドレスの検証を確認しようとしています

私たちは、GridViewフォームコントロールをいくつか検証しようとしています。

1つは電子メール制御です。

要件は次のとおりです。

まず、電子メールが入力されていることを確認します。これは機能します。 第2の要件はより困難です。この2番目の部分は、ユーザーが有効な電子メールアドレスを入力したことを確認することです。

私はいくつかの可能性を試しましたが、これまでに何も成し遂げていません。

jQueryを使用してGridViewで有効な電子メールアドレスを確認する方法はありますか?

<script type="text/javascript"> 
    $(function() { 
     $("[id*=GridView1] [id*=btnAdd]").click(function() { 
      //Find the GridView Row using the LinkButton reference. 
      var row = $(this).closest("tr"); 
      //Find the request type TextBox control. 
      var txtrequestType = row.find("[id*=txtrequestType]"); 
      var txtemailAdd = row.find("[id*=txtemailAdd]"); 

      //Find the DropDownList control. 
      // var ddlCountries = row.find("[id*=ddlCountries]"); 
      var message = ""; 
      //Validate the request type TextBox control. 
      if ($.trim(txtrequestType.val()) == "") { 
       message += "Please enter a new request type.\n"; 
      } 
      //Validate the email TextBox control. 
      if ($.trim(txtemailAdd.val()) == "") { 
       message += "Please enter a new email address.\n"; 
      } 
      // This validation is not working 
      if (!(txtemailAdd.indexOf('@') == -1)) { 
       message += "Please enter a valid email address.\n"; 
      } 
      //Validate the DropDownList control. 
      // if (ddlCountries.val() == "") { 
      //  message += "Please select Country."; 
      // } 
      //Display error message. 
      if (message != "") { 
       alert(message); 
       return false; 
      } 
      return true; 
     }); 
    }); 
</script> 
+1

あなたの条件付きロジックが後方であると ''存在する@ ... 'を取り除く場合にtrueを返します!' – charlietfl

+0

@charlietfl、本当にありがとうございました。それは私がここに投稿する前に試みた新しい解決策でしたが、その訂正を忘れました。それは今働いており、以下は働いていたスクリプトです。 – Kenny

答えて

0
if (($.trim(txtemailAdd.val()).indexOf('@') == -1)) { 
    message += "Please enter a valid email address.\n"; 
} 
関連する問題