![](/img/trans.png)
[英]Regex to match any set of numbers except the 10 digit numbers starting with 7
[英]Validation to check any email id or 10 digit numbers
我需要驗證一個文本框。用戶不應輸入任何郵件 ID,也不要輸入超過 10 的數字。請給出您的建議
由於其他人都在評論,請在發布您的問題之前嘗試做一些研究,因為以下所有答案僅取自本網站以前的答案。
您的查詢可以分為兩部分 -
您可以在 StackOverflow 上的此處和此處找到已回答的電子郵件驗證腳本。
對於 PHP 服務器端驗證,取自此處。
function validateEmail($email) {
return (bool) stripos($email,'@');
}
如果輸入的文本是電子郵件,則上述所有函數都將返回true
。 因此,您可能需要檢查false
條件,因為您不希望輸入電子郵件地址。
同樣,檢查輸入的數字不超過 10 個字符,您可以使用:-
簡單的
可以在此處找到 Javascript 驗證
但是,您的問題中仍然存在一些未處理的情況 - 當有人輸入正常文本但大於 10 個字符時會發生什么? 這應該被允許嗎? 理想情況下它應該是因為它不是電子郵件,它不是一個大於 10 位的數字?
<label> Student Mobile no : </label> <input type="text" name="country code" value="+91" size="2"/> <input type="tel" name="phone" size="10"/> <br> <br> <label> Guardian Mobile no : </label> <input type="text" name="country code" value="+91" size="2"/> <input type="tel" name="phone" size="10"/> <br> <br> <label for="email">Email :</label> <input type="email" placeholder="Enter Email" name="email" required>
只需在 HTML 表單的 input 標簽內使用 maxlength 作為文本類型輸入屬性,或者將 size 屬性用於電話類型輸入屬性。
對於電子郵件驗證,請在 HTML 表單的輸入標簽中使用 type = "number" 屬性。 請參考上面的代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.