in this function i want to add pan gstn mobile email validation please suggest
function ValidateForm() {
if ($("#txtname1").val() == '') {
//alert('Please Enter Name.');
return false;
}
}
Jayraj ChhayaPosted Jan 10, 2024, 9:15 AM
If you want to display an alert message when the name field is empty, you can uncomment the line
//alert('Please Enter Name.');by removing the double slashes at the beginning of the line. This will enable the alert message to be displayed.Here's the updated code:
To prevent the form from being submitted when the name field is empty, the current code is sufficient. However, if you want to add additional validation for PAN, GSTN, mobile, and email fields, you can modify the
ValidateForm()function accordingly.Here's an example of how you can add validation for PAN, GSTN, mobile, and email fields:
In the above example, I have added variables for PAN, GSTN, mobile, and email fields and performed validation checks similar to the name field. You can customize the validation logic for each field according to your requirements.
Remember to update the HTML code to include the appropriate input fields with the corresponding ids (
txtpan,txtgstn,txtmobile,txtemail) for the respective fields.Naimish MakwanaPosted Jan 10, 2024, 6:10 AM
Sure, I can help you add validation for PAN, GSTN, mobile, and email in your JavaScript function. Here’s how you can do it:
In this code, I’ve added regular expressions to validate PAN, GSTN, mobile, and email. You need to replace
$("#txtPan").val(),$("#txtGstn").val(),$("#txtMobile").val(), and$("#txtEmail").val()with the actual IDs of your input fields. If the validation fails, the function will returnfalse. You can uncomment the alert statements to show an alert to the user when the validation fails. Please note that this is a basic validation and might need to be adjusted based on your specific requirements. For example, the mobile number validation is very basic and checks only for 10 digits. It does not check for country codes or specific number patterns within different countries. Similarly, the email validation is also basic and checks for the presence of ‘@’ and ‘.’ symbols in the correct order. It does not check for valid top-level domains or the exact number of characters in each part of the email. You might want to adjust these regular expressions based on your requirements. Also, please be aware that client-side validation can be bypassed, so make sure to validate the data on the server side as well.Thanks
Amit MohantyPosted Jan 10, 2024, 6:01 AM
Sachin SinghPosted Jan 10, 2024, 5:29 AM
you can use this
Ramakrishnan RPosted Jan 10, 2024, 5:28 AM
To add PAN, GSTN, mobile, and email validation to your JavaScript function, you can modify it as follows:
This code includes validations for PAN, GSTN, mobile number, and email address. Make sure to replace
#txtpan,#txtgstn,#txtmobile, and#txtemailwith the appropriate IDs for your input fields.You can also customize the regular expressions (
panRegex,gstnRegex,mobileRegex,emailRegex) based on the specific validation requirements you have.