Disable cut, copy and paste in textbox using jquery, javascript

Category: JAVA SCRIPTJQUERY Comments: 6 comments


Disable cut, copy & paste using Javascript

  1. When we don’t want to display any message on cut, copy & paste

     

    1. <asp:TextBox ID=”TextBox1″ runat=”server” oncopy=”return false” onpaste=”return false” oncut=”return false”></asp:TextBox>

     

  2. When we want to display an alert message on copy, paste and cut

     

    1. <script language=”javascript” type=”text/javascript”>
    2. function DisableCopyPaste (e)
    3. {
    4. // Message to display
    5. var message = “Cntrl key/ Right Click Option disabled”;
    6. // check mouse right click or Ctrl key press
    7. var kCode = event.keyCode || e.charCode;
    8. //FF and Safari use e.charCode, while IE use e.keyCode
    9. if (kCode == 17 || kCode == 2)
    10. {
    11. alert(message);
    12. return false;
    13. }
    14. }
    15. </script>
    16. <asp:TextBox ID=”TextBox1″ runat=”server” onKeyDown=”return DisableCopyPaste(event)”onMouseDown=”return DisableCopyPaste (event)”></asp:TextBox>

     

Disable cut, copy & paste using JQuery

  1. <script type=”text/javascript”>
  2. $(document).ready(function() {
  3. $(‘#TextBox1′).bind(‘copy paste cut’,function(e) {
  4. e.preventDefault(); //disable cut,copy,paste
  5. alert(‘cut,copy & paste options are disabled !!’);
  6. });
  7. });
  8. </script>
  9. <asp:TextBox ID=”TextBox1″ runat=”server” ></asp:TextBox>

6 comments on “Disable cut, copy and paste in textbox using jquery, javascript

  1. shahrukhh on said:

    function getAge() {
    var dateString = document.getElementById(“txtAge”).value;

    var now = new Date();
    var today = new Date(now.getYear(), now.getMonth(), now.getDate());

    var yearNow = now.getYear();
    var monthNow = now.getMonth();
    var dateNow = now.getDate();

    var dob = new Date(dateString.substring(6, 10),
    dateString.substring(0, 2) – 1,
    dateString.substring(3, 5)
    );

    var yearDob = dob.getYear();
    var monthDob = dob.getMonth();
    var dateDob = dob.getDate();
    var age = {};
    var ageString = “”;
    var yearString = “”;
    var monthString = “”;
    var dayString = “”;

    yearAge = yearNow – yearDob;

    if (monthNow >= monthDob)
    var monthAge = monthNow – monthDob;
    else {
    yearAge–;
    var monthAge = 12 + monthNow – monthDob;
    }

    if (dateNow >= dateDob)
    var dateAge = dateNow – dateDob;
    else {
    monthAge–;
    var dateAge = 31 + dateNow – dateDob;

    if (monthAge 1) yearString = ” years”;
    else yearString = ” year”;
    if (age.months > 1) monthString = ” months”;
    else monthString = ” month”;
    if (age.days > 1) dayString = ” days”;
    else dayString = ” day”;

    if ((age.years > 0) && (age.months > 0) && (age.days > 0))
    ageString = age.years + yearString + “, ” + age.months + monthString + “, and ” + age.days + dayString + ” old.”;
    else if ((age.years == 0) && (age.months == 0) && (age.days > 0))
    ageString = “Only ” + age.days + dayString + ” old!”;
    else if ((age.years > 0) && (age.months == 0) && (age.days == 0))
    ageString = age.years + yearString + ” old. Happy Birthday!!”;
    else if ((age.years > 0) && (age.months > 0) && (age.days == 0))
    ageString = age.years + yearString + ” and ” + age.months + monthString + ” old.”;
    else if ((age.years == 0) && (age.months > 0) && (age.days > 0))
    ageString = age.months + monthString + ” and ” + age.days + dayString + ” old.”;
    else if ((age.years > 0) && (age.months == 0) && (age.days > 0))
    ageString = age.years + yearString + ” and ” + age.days + dayString + ” old.”;
    else if ((age.years == 0) && (age.months > 0) && (age.days == 0))
    ageString = age.months + monthString + ” old.”;
    else ageString = “Oops! Could not calculate age!”;

    //alert(ageString);
    document.getElementById(“lblAge”).innerHTML = ageString;

    }

    //alert(getAge(dateString));

  2. shahrukhh on said:

    Date of Birth :(mm/dd/yyyy)

    Age    :

  3. shahrukh on said:

    function FName() {
    debugger

    var fname = document.getElementById(“txtFName”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    return false;
    }
    else if (!(fname.value.charAt(0) === fname.value.charAt(0).toUpperCase())) {
    alert(“First letter should be a capital letter”);
    return false;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }
    }

    function LName() {
    var lname = document.getElementById(“txtLName”);

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    return false;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    }

    function validateMobileNo() {
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum== “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    return false;
    }
    else if(Mnum.length= 65 && keycode = 97 && keycode 31 && (charCode 57) {
    return false;
    }
    else if (charCode == 46 && (str.indexOf(“.”) != -1)) {
    return false;
    }
    else {
    return true;
    }
    }

    function dateformat(key) {
    var keycode = (key.which) ? key.which : key.keyCode;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if ((keycode == 8) || keycode == 9 || (keycode >= 47 && keycode 47 && keycode 47 && keycode < 58)) {
    return true;
    }
    else
    return false;
    }

    }

    function validateEmail() {
    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";

    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";

    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }
    }

    function validateDOB() {
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    return false;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    return false;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }

    }

    function validateUname() {
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    return false;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    }

    function validatePassword() {
    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    return false;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    }

    function validateCPwd() {
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    return false;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }
    }

    function validateForm() {
    var flag = 1;
    var fname = document.getElementById(“txtFName”);
    var lname = document.getElementById(“txtLName”);
    var male = document.getElementById(“rbtMale”);
    var female = document.getElementById(“rbtFemale”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }

    //last name validation

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    //gender validation

    if (male.checked != true && female.checked != true) {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “Please select the gender”;
    flag = 0;
    }
    else {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “”;
    }

    //mobile number checking
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum == “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    flag = 0;
    }
    else if (Mnum.length < 10) {
    document.getElementById("lblMNumErrMsg").innerHTML = "please enter the valid Mobile Number";
    flag = 0;
    }

    else {
    document.getElementById("lblMNumErrMsg").innerHTML = "";
    }
    //email validation

    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";
    flag = 0;
    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";
    flag = 0;
    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }

    //date of birth
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    flag = 0;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    flag = 0;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }
    //user name checking
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    flag = 0;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    flag = 0;
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    //passsword checking

    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    flag = 0;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    // confirm password
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    flag = 0;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    flag = 0;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }

    //whole page testing with flag

    if (flag == 0) {
    return false;
    }
    }

    //dropdownlist
    var e = document.getElementById(“ddlViewBy”);
    var strUser = e.options[e.selectedIndex].text;

    //new mail validation

    function ckEmail() {
    debugger
    var okd = [\'primetgi.com\']

    var emailRE = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+.[a-zA-Z]{2,4})$/
    var tst = document.getElementById(“txtEmail”).value;
    var aLst = emailRE.exec(tst)
    if (!aLst)
    alert(“a valid email address is reqiured”);

    var sLst = aLst[1].toLowerCase()
    for (var i = 0; i < okd.length; i++) {
    if (sLst == okd[i]) {
    return true
    }
    }

    alert("not a valid doamin");
    }

    var ckValid = ckEmail(tst);
    if (ckValid === true) {
    alert(ckValid) // placeholder for process validated
    } else {
    alert(ckValid) // placeholder for show error message
    }

  4. shahrukh on said:

    this is mail sending code…
    protected void btnSendmail_Click(object sender, EventArgs e)
    {
    string FEmailId = “mshaik@primetgi.com”;
    string TEmailId = txtEmail.Text;
    using (MailMessage mm = new MailMessage( TEmailId,FEmailId))
    {
    mm.Subject = “Reg: Registration Successful..”;
    string strComment = “your registration is successful.”;
    string uname = txtUName.Text;
    string Password = txtPwd.Text;
    string sign = “nnThanks,rnAccounts Department.”;
    mm.Body = strComment + “n” + uname + “n” + Password + “n” + sign;
    mm.IsBodyHtml = false;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = “mail.2xprime.com”;
    // smtp.EnableSsl = true;
    NetworkCredential NetWorkCred = new NetworkCredential(FEmailId, “prime”);
    smtp.UseDefaultCredentials = true;
    smtp.Credentials = NetWorkCred;
    smtp.Port = 25;//Gmail Port Number
    smtp.Send(mm);
    ClientScript.RegisterStartupScript(GetType(), “alert”, “Email sent successfull”);
    Response.Redirect(“Login page.aspx”);
    }
    }

  5. function FName() {
    debugger

    var fname = document.getElementById(“txtFName”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    return false;
    }
    else if (!(fname.value.charAt(0) === fname.value.charAt(0).toUpperCase())) {
    alert(“First letter should be a capital letter”);
    return false;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }
    }

    function LName() {
    var lname = document.getElementById(“txtLName”);

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    return false;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    }

    function validateMobileNo() {
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum== “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    return false;
    }
    else if(Mnum.length= 65 && keycode = 97 && keycode 31 && (charCode 57) {
    return false;
    }
    else if (charCode == 46 && (str.indexOf(“.”) != -1)) {
    return false;
    }
    else {
    return true;
    }
    }

    function dateformat(key) {
    var keycode = (key.which) ? key.which : key.keyCode;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if ((keycode == 8) || keycode == 9 || (keycode >= 47 && keycode 47 && keycode 47 && keycode < 58)) {
    return true;
    }
    else
    return false;
    }

    }

    function validateEmail() {
    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";

    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";

    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }
    }

    function validateDOB() {
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    return false;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    return false;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }

    }

    function validateUname() {
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    return false;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    }

    function validatePassword() {
    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    return false;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    }

    function validateCPwd() {
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    return false;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }
    }

    function validateForm() {
    var flag = 1;
    var fname = document.getElementById(“txtFName”);
    var lname = document.getElementById(“txtLName”);
    var male = document.getElementById(“rbtMale”);
    var female = document.getElementById(“rbtFemale”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }

    //last name validation

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    //gender validation

    if (male.checked != true && female.checked != true) {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “Please select the gender”;
    flag = 0;
    }
    else {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “”;
    }

    //mobile number checking
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum == “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    flag = 0;
    }
    else if (Mnum.length < 10) {
    document.getElementById("lblMNumErrMsg").innerHTML = "please enter the valid Mobile Number";
    flag = 0;
    }

    else {
    document.getElementById("lblMNumErrMsg").innerHTML = "";
    }
    //email validation

    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";
    flag = 0;
    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";
    flag = 0;
    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }

    //date of birth
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    flag = 0;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    flag = 0;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }
    //user name checking
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    flag = 0;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    flag = 0;
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    //passsword checking

    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    flag = 0;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    // confirm password
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    flag = 0;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    flag = 0;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }

    //whole page testing with flag

    if (flag == 0) {
    return false;
    }
    }

    //dropdownlist
    var e = document.getElementById(“ddlViewBy”);
    var strUser = e.options[e.selectedIndex].text;

    //new mail validation

    function ckEmail() {
    debugger
    var okd = [\'primetgi.com\']

    var emailRE = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+.[a-zA-Z]{2,4})$/
    var tst = document.getElementById(“txtEmail”).value;
    var aLst = emailRE.exec(tst)
    if (!aLst)
    alert(“a valid email address is reqiured”);

    var sLst = aLst[1].toLowerCase()
    for (var i = 0; i < okd.length; i++) {
    if (sLst == okd[i]) {
    return true
    }
    }

    alert("not a valid doamin");
    }

    var ckValid = ckEmail(tst);
    if (ckValid === true) {
    alert(ckValid) // placeholder for process validated
    } else {
    alert(ckValid) // placeholder for show error message
    }

  6. raghuveer on said:

    function FName() {
    debugger

    var fname = document.getElementById(“txtFName”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    return false;
    }
    else if (!(fname.value.charAt(0) === fname.value.charAt(0).toUpperCase())) {
    alert(“First letter should be a capital letter”);
    return false;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }
    }

    function LName() {
    var lname = document.getElementById(“txtLName”);

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    return false;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    }

    function validateMobileNo() {
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum== “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    return false;
    }
    else if(Mnum.length= 65 && keycode = 97 && keycode 31 && (charCode 57) {
    return false;
    }
    else if (charCode == 46 && (str.indexOf(“.”) != -1)) {
    return false;
    }
    else {
    return true;
    }
    }

    function dateformat(key) {
    var keycode = (key.which) ? key.which : key.keyCode;
    var charCode = (evt.which) ? evt.which : event.keyCode
    if ((keycode == 8) || keycode == 9 || (keycode >= 47 && keycode 47 && keycode 47 && keycode < 58)) {
    return true;
    }
    else
    return false;
    }

    }

    function validateEmail() {
    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";

    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";

    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }
    }

    function validateDOB() {
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    return false;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    return false;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }

    }

    function validateUname() {
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    return false;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    }

    function validatePassword() {
    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    return false;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    }

    function validateCPwd() {
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    return false;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }
    }

    function validateForm() {
    var flag = 1;
    var fname = document.getElementById(“txtFName”);
    var lname = document.getElementById(“txtLName”);
    var male = document.getElementById(“rbtMale”);
    var female = document.getElementById(“rbtFemale”);

    if (fname.value == “”) {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “please enter the First Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblFNameErrMsg”).innerHTML = “”;
    }

    //last name validation

    if (lname.value == “”) {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “please enter the Last Name”;
    flag = 0;
    }
    else {
    document.getElementById(“lblLNameErrMsg”).innerHTML = “”;
    }

    //gender validation

    if (male.checked != true && female.checked != true) {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “Please select the gender”;
    flag = 0;
    }
    else {
    document.getElementById(“lblGenderErrMsg”).innerHTML = “”;
    }

    //mobile number checking
    var Mnum = document.getElementById(“txtMNum”).value;

    if (Mnum == “” || Mnum == “+91″) {
    document.getElementById(“lblMNumErrMsg”).innerHTML = “please enter the Mobile Number”;
    flag = 0;
    }
    else if (Mnum.length < 10) {
    document.getElementById("lblMNumErrMsg").innerHTML = "please enter the valid Mobile Number";
    flag = 0;
    }

    else {
    document.getElementById("lblMNumErrMsg").innerHTML = "";
    }
    //email validation

    var emailPat = /^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$/;
    var emailid = document.getElementById("txtEmail").value;
    var matchArray = emailid.match(emailPat);

    if (document.getElementById("txtEmail").value == "") {
    // alert("Email id can not be blank");
    document.getElementById("lblEmailErrMsg").innerHTML = "enter email ";
    flag = 0;
    }

    else if (matchArray == null) {
    //alert("Your email address seems incorrect. Please try again.");
    document.getElementById("lblEmailErrMsg").innerHTML = "Incorrect mail";
    flag = 0;
    }
    else {
    document.getElementById("lblEmailErrMsg").innerHTML = "";
    }

    //date of birth
    var tdob;
    var dob = document.getElementById("txtDob");
    var pattern = /^d{4}[/-](0?[1-9]|1[012])[/-](0?[1-9]|[12][0-9]|3[01])$/;
    tdob = dob.value;
    if (tdob == "") {
    // alert("please enter dob");
    document.getElementById("lblDobErrMsg").innerHTML = "enter the dob";
    flag = 0;
    }
    else if (tdob == null || !pattern.test(tdob)) {
    //alert("please enter valid date ");
    document.getElementById("lblDobErrMsg").innerHTML = "enter valid date ";
    flag = 0;
    }
    else {
    document.getElementById("lblDobErrMsg").innerHTML = "";
    }
    //user name checking
    var uname = document.getElementById("txtUName").value;

    if (uname == "") {
    document.getElementById("lblUNameErrMsg").innerHTML = "Please enter the User Name";
    flag = 0;
    }
    else if (uname.length < 5) {
    document.getElementById("lblUNameErrMsg").innerHTML = "User Name should be Min 5 chars";
    flag = 0;
    }
    else {
    document.getElementById("lblUNameErrMsg").innerHTML = "";
    }

    //passsword checking

    var pwd = document.getElementById("txtPwd").value;

    if (pwd == "") {
    document.getElementById("lblPwdErrMsg").innerHTML = "Please enter the password";
    flag = 0;
    }
    else if (pwd.length 5) {
    document.getElementById(“lblPwdErrMsg”).style.color = “green”;
    document.getElementById(“lblPwdErrMsg”).innerHTML = “password is Strong!”;

    }
    else {
    document.getElementById(“lblPwdErrMsg”).innerHTML = “”;
    }

    // confirm password
    var pwd = document.getElementById(“txtPwd”);
    var cpwd = document.getElementById(“txtCPwd”);

    if (cpwd.value == “”) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Please Confirm the password”;
    flag = 0;
    }
    else if (cpwd.value != pwd.value) {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “Incorrect Password !!”;
    flag = 0;
    }
    else {
    document.getElementById(“lblCPwdErrMsg”).innerHTML = “”;
    }

    //whole page testing with flag

    if (flag == 0) {
    return false;
    }
    }

    //dropdownlist
    var e = document.getElementById(“ddlViewBy”);
    var strUser = e.options[e.selectedIndex].text;

    //new mail validation

    function ckEmail() {
    debugger
    var okd = [\'primetgi.com\']

    var emailRE = /^[a-zA-Z0-9._+-]+@([a-zA-Z0-9.-]+.[a-zA-Z]{2,4})$/
    var tst = document.getElementById(“txtEmail”).value;
    var aLst = emailRE.exec(tst)
    if (!aLst)
    alert(“a valid email address is reqiured”);

    var sLst = aLst[1].toLowerCase()
    for (var i = 0; i < okd.length; i++) {
    if (sLst == okd[i]) {
    return true
    }
    }

    alert("not a valid doamin");
    }

    var ckValid = ckEmail(tst);
    if (ckValid === true) {
    alert(ckValid) // placeholder for process validated
    } else {
    alert(ckValid) // placeholder for show error message
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

HTML tags are not allowed.