TECHNICALSTUDY

The associate of technical study article for computer science students which could gain the knowledge about to technicals like Computer history, hard disk, printer,central processing unit etc. Technicalstudy also considered software engineering, operating system and some chunks of programming languages.

Email subscription

Enter your email address:

Delivered by FeedBurner

Friday, September 15, 2023

Javascript and JQuery Validation Regex Code by Condition

-Client Side Validation - 


Point 1- Don't Contain Space :


var pattern = /^\S*$/;
var username = $("#username").val();
if(pattern.test(username))
{
$(".error-username").css("display", "none");

}
else
{
$("#username").val("");
$(".error-username").css("color", "red");
$(".error-username").css("display", "block");
}
});

Point 2 - Phone Validation : 

$("#phone").blur(function(){
var pattern = /^\d{10}$/;
var phone = $("#phone").val();
if(pattern.test(phone))
{
// alert("hello");
$("#mobilecheck").text("");
$("#mobilecheck").css("display", "none");
$("#validmobilecheck").css("display", "block");
$(".error-message").css("display", "none");
teachphone = true;
Editteachphone = true;
}
else
{
$("#mobilecheck").text("please enter numbers only");
$("#mobilecheck").css("display", "block");
$("#validmobilecheck").css("display", "none");
teachphone = false;
Editteachphone = false;
}
});


Point 3-  Alphabet and Space (Only character) Validation : 

$("#Intiprincipal").blur(function(){
var onlycharacter =/^[a-zA-Z\s]+$/;
if(!onlycharacter.test(instituteadd))
{
$('#Instprincipal').text('Alphabet and space allowed');
$('#Instprincipal').css('color','red');
$('#Instprincipal').css('display','block');
$('#Intiprincipal').val('');
}else{
$('#Instprincipal').text('');
$('#Instprincipal').css('display','none');
}
});


Point 4- Email Validation : 


$("#email").blur(function() {
var pattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var email = $("#email").val();
if(pattern.test(email))
{
$("#emailcheck").text("");
$("#emailcheck").css("display", "none");
$("#validemailcheck").css("display", "block");
}
else
{
$("#emailcheck").text("please enter valid email");
$("#emailcheck").css('color','red');
$("#emailcheck").css("display", "block");
$("#validemailcheck").css("display", "none");
}
});

No comments:

Post a Comment

Adbox