我設計了一個帶有點擊功能的表單,該表單的功能是幫助用戶驗證他們的電話號碼是否被其他人在我的網站上使用過。
如果他們提供的電話號碼以前被使用過,他們將收到一個通知,讓他們登錄。
如果他們的電話號碼沒有被使用過,他們將被重定向到下一個頁面。
在我的國家,電話號碼的數字是11位,然而,我注意到,如果用戶輸入任何數字,他們仍然會被重定向到下一頁,而不是得到一個錯誤資訊,說"無效的電話號碼格式"
。我如何在我的表單中添加電話號碼驗證? 確保用戶輸入11位數字? 并阻止我的表單重定向,除非用戶輸入正確的電話號碼格式。
感謝任何幫助和糾正。
下面是我的代碼。
。/* myScript.js */
function check(form) /* function to check userid & password*/ {
/*下面的代碼將檢查輸入的userid和密碼是否匹配*/ {
if (form.usercheck1.value == "1234"/span> ||
form.usercheck1.value == "12345" !
) {
alert("這個電話號碼已經存在一個賬戶!請繼續登錄。
請登錄以繼續。") /*顯示錯誤資訊*/。
} else if (form.usercheck1. value == "" || form.usercheck1.value == null) {
alert(" Please provide your phone number!")。
} else {
window.location.replace('https://www.google.com'/span>)
/*打開目標頁面,同時Id & password匹配*/
<link href="https://dl.dropbox.com/s/n2rdyum6kwm7hny/Loginin%20Button%20Animation. css" rel="stylesheet" type="text/css"></link><link="https://dl. dropbox.com/s/qprekw79zsldo2b/input%20box。 css" rel="stylesheet" type="text/css"></link>/span>
< div class="bg-img"/span>>
<div class=" separator" style="clear: both; text-align: center;">
<br /></div>
<div class="分離器" style="清除。both; text-align: center;">
< img border="0"/span> data-original-height="512"/span> data-original-width="512" height="230" src="https: //1. bp.blogspot.com/-EZYNAhXAq1M/YGbnrRsFYeI/AAAAAAAMU/6rGjRKv9UvMGn3doDe5_kT1WbOUFZjzUACLcBGAsYHQ/0/administartor. gif" width="220" /></div>
<div style="text-align: center;"><span style="font-family: Architects Daughter; font-size: medium;"><b>新注冊</b> </span></div>
<div style="text-align: center;"><span style="color: red; font-family: Courgette;"><b>檢查您的電話號碼是否在我們的平臺上未被使用<。 b></span></div>>
<div style="text-align: center;"><span style="color: red; font-family: Courgette;"><b>before you proceed. </b>< span></div>>
<div style="text-align: center;"><span style="font-family: Architects Daughter; font-size: medium;"><b>在下面輸入你的電話號碼。 </b>< span></div>>
<div style="text-align: center;">/span>
< form autocomplete="off"/span> id="formName" name="formName">
< input class="input5"/span> maxlength="11" id="myform_phone"/span> name="usercheck1"/span> oninput="this. value = this.value.replace(/[^0-9.]/g, '').replace(/(.*?).*/g, '1');" style="font-family: Courgette;" type="text" placeholder="Phone number here..." />
<br />
<center>< button class="button" onclick="check(this. form)" type="button" value="> <span> 進行</span>< button></center>
</form>/span>
<iframe name="sif1" sandbox="allow-form allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
你可以在輸入上使用一個pattern屬性(更多資訊)。它指定了一個值應該匹配的重碼。如果你想只得到11個數字,你可以把它設定成這樣的:
< input name="usercheck1" pattern=" [0-9]{11}" 。 ...其余 of your code />
或者你可以將輸入型別設定為number,并將minlength和maxlength設定為11。
uj5u.com熱心網友回復:
如何將驗證添加到你的javascript中
else if (form.usercheck1.value.length<11 || form.usercheck1.value.length>11) { alert("電話號碼應該是11位數!");}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/309062.html
標籤:
