Name Validation Using Java Script
Name Validation Using Java Script
//Name validation:
//Name Format--: MD.XXXXX XXXX_XXXX_XXXX
//accept only one space
//accept only one dot
//accept less than 50 char
//accept greater equal 3 char
//number is not allow
function name_Validation()
{
var nameFiled = document.getElementById('nameField');
if(nameField.value=="" || nameField.value==null)
{
display_msg("nameField", "Required", "red", "msg_name");
}
else {
//display_msg("nameField", "Done", "green", "msg_name");
var name = nameField.value;
var i;
var entered_name = "valid";
var space_Count=0;
var dot_Count=0;
for(i=0;i<name.length;i++)
{
if(name[i]>='a' && name[i]<='z' || name[i]>='A' && name[i]<='Z' || name[i]==" " || name[i]=="." || name[i]=="_")
{
if (name[i] == " ")
{
space_Count++;
}
else if (name[i] == ".")
{
dot_Count++;
}
}
else {
entered_name = "invalid";
}
}
if(entered_name=="valid")
{
if (name.length > 50) {
display_msg("nameField", "Your name is too big", "red", "msg_name");
}
else if(name.length<=3)
{
display_msg("nameField", "Your name is too short", "red", "msg_name");
}
else if(space_Count>1)
{
display_msg("nameField", "Extra space found", "red", "msg_name");
}
else if (dot_Count > 1) {
display_msg("nameField", "Extra dot found", "red", "msg_name");
}
else {
display_msg("nameField", "Done", "green", "msg_name");
}
}
else {
display_msg("nameField", "Invalid name enter", "red", "msg_name");
}
}
}
function hide(msg_hide_id)
{
var error_msg = document.getElementById(msg_hide_id).style.visibility = "hidden";
}
<form>
<br />
Enter Your NAME :
<input type="text" id="nameField" onclick="hide('msg_name')" />
<span id="msg_name"></span> <br /><br />
<input type="button" value="SUBMIT" onclick="name_Validation()"/>
</form>
//Try this javascript method on your script
স্বপ্নের প্রতিবিম্ব...
মন্তব্যসমূহ
একটি মন্তব্য পোস্ট করুন