Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form name = "form1">
- <label>Username</label><br>
- <input id="username" name="username" type="text" minlength="5" maxlength="8" required ><br>
- <label>First Name</label><br>
- <input id="firstName" type="text" required><br>
- <label>Last Name</label><br>
- <input id="lastName" type="text" required><br>
- <label>E-mail</label><br>
- <input id="email" type="text" required><br>
- <label>Password</label><br>
- <input id="password" type="password" minlength="7" required><br>
- <label>Mobile Number</label><br>
- <input id="mobileNumber" type="tel" pattern="[0]{1}[1]{1}[0-9]{9}" required><br>
- <input type="button" value="Submit" id="submit" onclick="validations()"/>
- </form>
- <script>
- var email = document.getElementById("email");
- var username = document.getElementById("username");
- var firstName = document.getElementById("firstName");
- var lastName = document.getElementById("lastName");
- var reg = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}$/;
- var txt = /^[a-zA-z]+$/;
- var password = document.getElementById("password");
- function validations(){
- //empty validations
- if(username.value == "" || email == "" || firstName.value == "" || lastName.value == "" || password.value == ""){
- alert("Error! Empty field(s)")
- }
- if(username.textLength < 5 || username.textLength > 8){
- alert("Error! Invalid username")
- console.log(!txt.test(un.value))
- }
- else if(reg.test(email.value)){
- alert("Error! Invalid email")
- console.log(!txt.test(em.value))
- }
- else if(password.textLength < 8){
- alert("Error! Invalid password")
- console.log(password);
- }
- else if(!txt.test(firstName.value)){
- alert("Error! Invalid first name")
- console.log(!txt.test(firstName.value))
- }
- else if(!txt.test(lastName.value)){
- alert("Error! Invalid first name")
- console.log(!txt.test(lastName.value))
- }
- else{
- alert("Welcome!")
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement