Simple password box judgment

Simple password box judgment

(1) After the user enters a user name, the user loses focus to verify the user name and gives a corresponding prompt: Requirements: a. The string cannot be empty b. The length is between 6-20 c. Cannot start with a number d. Can only contain numbers, letters, and underscores
insert image description here
var oNames = document.getElementById('names');//Look for nodes
var oInport = document.getElementById('inport');
oNames.onblur = function(){//Setting fails Focus event
var a = oNames.value;//Get the content of the input box
var b=0;
//Make a series of judgments, the method I use here to eliminate errors
if(a==''){ oInport.innerHTML = 'String cannot be empty' }else if(a.length<6||a.length>20){ oInport.innerHTML = 'length 6-20' }else if(a[0]>'0'&&a[ 0]<'9'){ oInport.innerHTML = 'cannot begin with a number' }else{ for(var i=0;i<a.length;i++){ if(a[i]







'_' || a[i]>='0'&&a[i]<='9' || a[i]>='a'&&a[i]<='z' || a[i]> ='A'&&a[i]<='Z'){ b++; }else{ oInport.innerHTML = 'Can only contain numbers, letters, underscores'; break; } } if(b






==a.length){ oInport.innerHTML = 'correct' }

}
}

Guess you like

Origin blog.csdn.net/moanuan/article/details/103405852