Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript HTML5表单验证自定义_Javascript_Html_Contact Form - Fatal编程技术网

Javascript HTML5表单验证自定义

Javascript HTML5表单验证自定义,javascript,html,contact-form,Javascript,Html,Contact Form,我已经使用HTML5表单创建了一个网站。我在所有字段中都使用了“required”。因此,它会阻止将表单提交为空。但是,它不能处理所有字段的正确语法。请参阅我使用过的输入类型=“text”、“tel”、“number”、“date”等。如果有人在date/number/tel处输入单词,仍然可以接受!如果有人不在收音机上打勾,那也是可以接受的。我想,如果我使用HTML5表单,我不需要使用javascript进行验证。但是,也许是我现在需要的。因此,在不改变任何设计/样式的情况下,如果没有日期、电

我已经使用HTML5表单创建了一个网站。我在所有字段中都使用了“required”。因此,它会阻止将表单提交为空。但是,它不能处理所有字段的正确语法。请参阅我使用过的输入类型=“text”、“tel”、“number”、“date”等。如果有人在date/number/tel处输入单词,仍然可以接受!如果有人不在收音机上打勾,那也是可以接受的。我想,如果我使用HTML5表单,我不需要使用javascript进行验证。但是,也许是我现在需要的。因此,在不改变任何设计/样式的情况下,如果没有日期、电话、号码等正确语法,我怎么能不允许提交表单?我已经在firefox上检查了所有内容。在chrome,firefox的一切都是一样的。只需输入type=“date”,chrome确保输入正确的日期

必要的HTML代码:

<div class="wrapper">
        <header class="page_title">
            <h1>Create New Job</h1>
        </header>
        <section class="form">
            <form id="form" name="form" method="post" action="#">
                <label>Job ID:</label>
                <input type="text" name="job_id" id="job_id" placeholder="1" required />
                <label>Start Date:</label>
                <input type="date" name="start_date" id="start_date" placeholder="mm/dd/yy" required>
                <label>Deadline:</label>
                <input type="date" name="deadline" id="deadline" placeholder="mm/dd/yy" required>
                <label>Finish Date:</label>
                <input type="date" name="finish_date" id="finish_date" placeholder="mm/dd/yy" required>
                <label>Budget($):</label>
                <input type="number" name="Budget" id="Budget" placeholder="100" required>
                <label>Client ID:</label>
                <input type="text" name="client_id" id="client_id" placeholder="1" required />
                <label>Client Phone Number:</label>
                <input type="tel" name="phone" id="phone" placeholder="01712345891" required />
                <label>Bidder ID:</label>
                <input type="text" name="bidder_id" id="bidder_id" placeholder="1" required />
                <label>Number of Supervisor:</label>
                <select title="Supervisor">
                        <option>1</option>
                        <option>1</option>
                        <option>2</option>
                        <option>3</option>
                </select>
                <label>Odesk Profile ID:</label>
                <input type="url" name="odesk_id" id="odesk_id" placeholder="https://www.odesk.com/jobs/Frontend-engineer" required>
                <label>Owner Type:</label>
                <input type="radio" name="owner_type" id="owner_type" value="member" /><label class="text_label">Member</label>
                <input type="radio" name="owner_type" id="owner_type" value="employee" /><label class="text_label">Employee</label>
                <div class="clear"></div>
                <label>Message:</label> 
                <textarea id="message" name="message" rows="2" cols="20" placeholder="Your enquiry goes here" required></textarea>
                <input type="submit" name="submit" id="submit" value="Submit">
            </form>
        </section>
 </div>
回到那时,(至少大多数)浏览器没有实现HTML5验证。您现在可以使用给定的代码,并将进行验证

即便如此,像“tel”这样的字段也不能像预期的那样工作。然后,我通常使用,它验证RegExp

例如:

<input type="text" name="job_id" id="job_id"
    placeholder="1" required pattern="\d+"/>


如果您想要进一步的验证功能,我建议您使用

是的,您需要使用JavaScript。
<input type="text" name="job_id" id="job_id"
    placeholder="1" required pattern="\d+"/>