使用者註冊介面js校驗+表單提示
阿新 • • 發佈:2019-01-26
// 使用者名稱
function YHMonblus(){
var username=document.getElementById("username");
// var reN =/^\d{6,18}$/;
var re = /^[a-zA-Z_]{6,18}$/;
if(username.value==""){
document.getElementById('YHMerror').innerText="請輸入使用者名稱";
}
else if(username.value.length < 6 ||username.value.length > 18){
console.log(username.value);
document.getElementById('YHMerror').innerText="格式錯誤,長度應為6-18個字元";
}
else if(!re.test(username.value)){
document.getElementById('YHMerror').innerText="格式錯誤,只能包含英文字母和下劃線";
}
else {
document.getElementById('YHMerror').innerText ="";
}
}
function YHMonfocu(){
document.getElementById('YHMerror').innerText ="";
}
// 密碼
function MMonblus(){
var password=document.getElementById("password");
var re = /^(?=.*\d)(?=.*[a-zA-Z])[\da-zA-Z]{6,}$/ ;
// var reg=/[A-Za-z].*[0-9]|[0-9].*[A-Za-z]/;
if(password.value==""){
document.getElementById('MMerror').innerText="請輸入密碼";
}
else if(password.value.length < 6){
document.getElementById('MMerror').innerText="格式錯誤,,密碼長度至少為6位";
}
else if(!re.test(password.value)){
document.getElementById('MMerror').innerText="格式錯誤,必須包含英文字母大小寫和數字";
}
else {
document.getElementById('MMerror').innerText ="";
}
}
function MMonfocu(){
document.getElementById('MMerror').innerText ="";
}
// 確認密碼
function QRMMonblus(){
var password=document.getElementById("password");
var confirmPassword=document.getElementById("confirmPassword");
if(confirmPassword.value==""){
document.getElementById('QRMMerror').innerText="請輸入確認密碼";
}
else if(password.value != confirmPassword.value){
document.getElementById('QRMMerror').innerText="兩次密碼輸入不一致";
}
else {
document.getElementById('QRMMerror').innerText ="";
}
}
function QRMMonfocu(){
document.getElementById('QRMMerror').innerText ="";
}
// 性別
function XBonblus(){
// var radios = document.getElementsByName("gender");
// if(radios.checked == false){
// document.getElementById('XBerror').innerText="請選擇性別";
// }else {
// document.getElementById('XBerror').innerText ="";
// }
}
function XBonfocu(){
// document.getElementById('XBerror').innerText ="";
}
// 愛好
function AHonblus(){
var hobbys = document.getElementsByName("hobby");
if(hobbys[0].checked == false&&hobbys[1].checked == false&&hobbys[2].checked == false){
document.getElementById('AHerror').innerText="請選擇愛好";
}else {
document.getElementById('AHerror').innerText ="";
}
}
function AHonfocu(){
document.getElementById('AHerror').innerText ="";
}
// 聯絡電話
function LXDHonblus(){
var phone=document.getElementById("phone");
var re = /^1\d{10}$/;
if(phone.value==""){
document.getElementById('LXDHerror').innerText="請輸入聯絡電話";
}
else if(!re.test(phone)){
document.getElementById('LXDHerror').innerText="電話格式輸入錯誤";
}
else {
document.getElementById('LXDHerror').innerText ="";
}
}
function LXDHonfocu(){
document.getElementById('LXDHerror').innerText ="";
}
// 電子郵箱
function DZYXonblus(){
var email=document.getElementById("email");
var re= /[a-zA-Z0-9]{1,10}@[a-zA-Z0-9]{1,5}\.[a-zA-Z0-9]{1,5}/;
if(email.value==""){
document.getElementById('DZYXerror').innerText="請輸入電子郵箱";
}
else if(!re.test(email.value)){
document.getElementById("DZYXerror").innerHTML="郵箱格式不正確";
}
else {
document.getElementById('DZYXerror').innerText ="";
}
}
function DZYXonfocu(){
document.getElementById('DZYXerror').innerText ="";
}