Answers for "username validation"

0

username validation

<html>
<head>
	<title></title>
</head>
<body>
<form method="post" action="">
	username:<input type="text"  id="name" onkeyup="validation()">
	</form>
</body>
<script type="text/javascript">
	function validation(){
	var username=document.getElementById("name").value;///get id with value 
	var usernamepattern=/^[A-Za-z .]{3,15}$/;////Regular expression
	if(usernamepattern.test(username))
	{
		document.getElementById("name").style.backgroundColor='yellow';
    }
    else
    {
    	document.getElementById("name").style.backgroundColor='red'; }
	}

</script>
</html>
Posted by: Guest on January-24-2021
0

username validation

const checkUsername = () => {

    let valid = false;
    const min = 3,
        max = 25;
    const username = usernameEl.value.trim();

    if (!isRequired(username)) {
        showError(usernameEl, 'Username cannot be blank.');
    } else if (!isBetween(username.length, min, max)) {
        showError(usernameEl, `Username must be between ${min} and ${max} characters.`)
    } else {
        showSuccess(usernameEl);
        valid = true;
    }
    return valid;
}Code language: JavaScript (javascript)
Posted by: Guest on April-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language