양식 제출 유효성 검사 제출 데이터 코드

11267 단어
 1    
 2      <br>        //              ( /  )
<span style="color:#008080;"> 3</span>         <span style="color:#0000ff;">function</span><span style="color:#000000;"> isNull(str){
</span><span style="color:#008080;"> 4</span>             <span style="color:#0000ff;">if</span> ( str == "" ) <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">true</span><span style="color:#000000;">;
</span><span style="color:#008080;"> 5</span>             <span style="color:#0000ff;">var</span> regu = "^[ | ]+$"<span style="color:#000000;">;
</span><span style="color:#008080;"> 6</span>             <span style="color:#0000ff;">var</span> re = <span style="color:#0000ff;">new</span><span style="color:#000000;"> RegExp(regu);
</span><span style="color:#008080;"> 7</span>             <span style="color:#0000ff;">return</span><span style="color:#000000;"> re.test(str);
</span><span style="color:#008080;"> 8</span> <span style="color:#000000;">        }
</span><span style="color:#008080;"> 9</span> 
<span style="color:#008080;">10</span>         <span style="color:#0000ff;">function</span><span style="color:#000000;"> check(){
</span><span style="color:#008080;">11</span>             <span style="color:#0000ff;">var</span> lname = $("#last_name"<span style="color:#000000;">);
</span><span style="color:#008080;">12</span>             <span style="color:#0000ff;">if</span>(lname.val()=="  " || isNull($("#last_name"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">13</span>             lname.addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">14</span> <span style="color:#000000;">            lname.focus();
</span><span style="color:#008080;">15</span>             <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">16</span> <span style="color:#000000;">            }            
</span><span style="color:#008080;">17</span>         
<span style="color:#008080;">18</span>             <span style="color:#0000ff;">if</span>($("#mobile").val()=="    " || isNull($("#mobile"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">19</span>             $("#mobile").addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">20</span>             $("#mobile"<span style="color:#000000;">).focus();
</span><span style="color:#008080;">21</span>             <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">22</span> <span style="color:#000000;">            }
</span><span style="color:#008080;">23</span>         
<span style="color:#008080;">24</span>             <span style="color:#0000ff;">var</span> email = $('#email'<span style="color:#000000;">).val();
</span><span style="color:#008080;">25</span>             <span style="color:#0000ff;">var</span> reg = /\w+[@]{1}\w+[.]\w+/<span style="color:#000000;">;
</span><span style="color:#008080;">26</span>             <span style="color:#0000ff;">if</span><span style="color:#000000;">(reg.test(email)){
</span><span style="color:#008080;">27</span>               <span style="color:#0000ff;">if</span>($('#email').hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">28</span>                 $('#email').removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">29</span> <span style="color:#000000;">              }
</span><span style="color:#008080;">30</span>             }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">31</span>                 $('#email').addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">32</span>                 $('#email'<span style="color:#000000;">).focus();
</span><span style="color:#008080;">33</span>                 <span style="color:#0000ff;">return</span> <span style="color:#0000ff;">false</span><span style="color:#000000;">;
</span><span style="color:#008080;">34</span> <span style="color:#000000;">            }        
</span><span style="color:#008080;">35</span> <span style="color:#000000;">        }
</span><span style="color:#008080;">37</span> 
<span style="color:#008080;">38</span>         $(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">39</span>             $('#last_name').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">40</span>                 <span style="color:#0000ff;">if</span>($("#last_name").val()=="  " || isNull($("#last_name"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">41</span>                 $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">42</span>                 }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">43</span>                   <span style="color:#0000ff;">if</span>($("#last_name").hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">44</span>                   $("#last_name").removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">45</span> <span style="color:#000000;">                  }
</span><span style="color:#008080;">46</span> <span style="color:#000000;">                }
</span><span style="color:#008080;">47</span> <span style="color:#000000;">            });
</span><span style="color:#008080;">48</span>             
<span style="color:#008080;">49</span>             $('#mobile').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">50</span>                 <span style="color:#0000ff;">if</span>($("#mobile").val()=="    " || isNull($("#mobile"<span style="color:#000000;">).val())){
</span><span style="color:#008080;">51</span>                 $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">52</span>                 }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">53</span>                   <span style="color:#0000ff;">if</span>($(<span style="color:#0000ff;">this</span>).hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">54</span>                   $(<span style="color:#0000ff;">this</span>).removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">55</span> <span style="color:#000000;">                  }
</span><span style="color:#008080;">56</span> <span style="color:#000000;">                }
</span><span style="color:#008080;">57</span> <span style="color:#000000;">            });
</span><span style="color:#008080;">58</span>             
<span style="color:#008080;">59</span>             $('#email').blur(<span style="color:#0000ff;">function</span><span style="color:#000000;">(){
</span><span style="color:#008080;">60</span>                 <span style="color:#0000ff;">var</span> email = $(<span style="color:#0000ff;">this</span><span style="color:#000000;">).val();
</span><span style="color:#008080;">61</span>                 <span style="color:#0000ff;">var</span> reg = /\w+[@]{1}\w+[.]\w+/<span style="color:#000000;">;
</span><span style="color:#008080;">62</span>                 <span style="color:#0000ff;">if</span><span style="color:#000000;">(reg.test(email)){
</span><span style="color:#008080;">63</span>                   <span style="color:#0000ff;">if</span>($(<span style="color:#0000ff;">this</span>).hasClass('rborder'<span style="color:#000000;">)){
</span><span style="color:#008080;">64</span>                     $(<span style="color:#0000ff;">this</span>).removeClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">65</span> <span style="color:#000000;">                  }
</span><span style="color:#008080;">66</span>                 }<span style="color:#0000ff;">else</span><span style="color:#000000;">{
</span><span style="color:#008080;">67</span>                     $(<span style="color:#0000ff;">this</span>).addClass('rborder'<span style="color:#000000;">);
</span><span style="color:#008080;">68</span> <span style="color:#000000;">                }
</span><span style="color:#008080;">69</span> <span style="color:#000000;">            });
</span><span style="color:#008080;">70</span>             
<span style="color:#008080;">71</span> <span style="color:#000000;">        })
</span><span style="color:#008080;">72</span>         


 
전재 대상:https://www.cnblogs.com/lola/p/6053733.html

좋은 웹페이지 즐겨찾기