如何在表单提交中验证模式

Atu*_*uka 8 html5

在给出edittext字段中输入的时候,如果有人将IP地址的IP地址格式放入应该像这些000.000.0.000 plz帮助我那么显示错误

在HTML5中: -

<div data-role="content">
     <form id="form">
         <div data-role="fieldcontain">
                    <label for="ip">IP Address/System Name</label>
                    <input name="ip" id="ip" type="text" pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">                       
         </div>
         <div style="text-align:center;">                   
                    <div data-role="button" data-theme="b" data-inline="true" id="button1">Update</div>
         </div> 
</div>
Run Code Online (Sandbox Code Playgroud)

Try*_*elf 11

要使HTML5验证处理提交,您必须required在您的input字段中放置属性,您要使用HTML5进行验证,并且您必须提交表单.

你可以处理通过javascript提交的表单数据,并且你想要手动处理提交的数据然后你必须data-ajax="false"在你的form标签中指定

对于您的代码,请尝试此操作

<div data-role="content">
 <form id="form" data-ajax="false">
     <div data-role="fieldcontain">
                <label for="ip">IP Address/System Name</label>
                <input name="ip" id="ip" type="text" required pattern="((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$">                       
     </div>
     <div style="text-align:center;">                   
                <input type="submit" value="Submit button" />
     </div> 
 </form>
</div>
Run Code Online (Sandbox Code Playgroud)

在javascript中你可以做类似的事情

$("#form").submit(function(e){
    e.preventDefault();
    //call your method

});
Run Code Online (Sandbox Code Playgroud)