Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
var name, reg;
Name = document.getElementById("txt_name").value;
           regno = document.getElementById("txt_reg_no").value;
           if (Name == '' && regno == '') {
               alert("Enter All Fields");
               return false;
           }
           if (Name == '') {
               alert("Please Enter Name");
               return false;
           }
           if (regno == '') {
               alert("Please Enter Reg. no ");
               return false;
           }


here i want result like
1. field name sholud accept only characters
2. field two accept only characters and numbers.

i want such a kind of validation expression

plz help me
Posted
Updated 19-Jun-14 19:01pm
v2
Comments
Sergey Alexandrovich Kryukov 20-Jun-14 0:53am    
Not clear. It all depends on what you want to achieve, what to validate, to what criteria...
—SA
_Asif_ 20-Jun-14 0:59am    
What do you mean by Validation Expression?
Namith Krishnan E 20-Jun-14 1:06am    
Are u using asp.net?
sanjaysgh 20-Jun-14 1:18am    
yes

try with RegExp

JavaScript
var reg1 = new RegExp('^[a-zA-Z]+$');
if (!reg1.test(Name)) {
    alert("Invalid Name");
    return false;
}

var reg2 = new RegExp('^[a-zA-Z0-9]+$');
if (!reg2.test(regno)) {
    alert("Invalid regno");
    return false;
}
DEMO[^]
 
Share this answer
 
v3
U can use regular expression validator in ASP.NET for this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900