我是JS新手,試圖獲得它,所以當有人在字段中輸入SSN號碼時,會給他們一個警告,告訴他們不要在其中放置SSN號碼。無法獲得JavaScript SSN表單驗證才能正常工作
HTML:
<form name="card" action="#">
<input type="text" name="field" class="name social" size="60" placeholder="First and Last Name">
<input type="text" name="field" class="phone social" size="60" placeholder="Phone Number">
<input type="text" name="field" class="email social" size="60" placeholder="Email([email protected])">
<select class="select">
<option value="My card has not yet arrived">My card has not yet arrived
<option value="Direct Deposit">Direct Deposit
<option value="Suggest a Card">Suggest a Card
<option value="Issues with CARD.com">Issues with CARD.com
<option value="Other">Other
</select>
<textarea name="field" class="text social " cols="60" rows="5" placeholder="How can we help you?"></textarea>
<input type"submit" name="submit" class="subBtn" value="Submit" onclick="warnCC(document.card.field)">Submit</input>
</form>
JS:
<script>
function warnCC()
{
var ssn = document.getElementsByTagName("input");
// document.getElementsByClassName("social");
var pattern = /^[0-9]{3}\-?[0-9]{2}\-?[0-9]{4}$/;
if (ssn.value.match(pattern))
{
return true;
alert("Please Do Not Enter SSN Info Into This Form");
}
else
{
return false;
alert("yay!")
}
}
</script>
在哪裏我凸輪走錯了任何幫助將是非常有益的。如果任何人都可以給我建議,我寧願它是在「onfocusout」上完成。
返回true _before_警報行可能會導致看到警報時出現問題。 –
您是否看到錯誤?這對帖子有幫助,或者至少不是你期望的行爲。 –