Case 1
If the validation is not for the last field of the form to be filled out, follow the steps given below.
- Set the onfocusout event for this button, as shown below.
- <div>Email Id: <input type="number" id="emailid" onfocusout="emailcheck();"></div>
- Create a function representing linked to that button and it gets executed when triggered.
- function mobilecheck() {
- var mobile = document.getElementById("phonenumber").value;
- var pattern = /^[1-9]{1}[0-9]{9}$/;
-
- if (pattern.test(mobile)) {
-
- return true;
- }
- alert("It is not a valid mobile number. Please input 10 digits only!");
- return false;
- }
Case 2
If the validation is the last field of the form to be filled (as displayed below), follow the steps given below to avoid multiple alert messages for the wrong Email entry.
- Add the Email validation code given below for the adding function.
- function addparty() {
- var partyname = $("#partyname").val();
- var address = $("#address").val();
- var phonenumber = $("#phonenumber").val();
- var contact = $("#contact").val();
- var emailid = $("#emailid").val();
-
- var caseid = $("#txt_caseidhidden").val();
- var caseidvalidation = $("#caseid_lb").text();
- if (caseidvalidation == "" || caseidvalidation == null || caseidvalidation == "NA" || caseidvalidation == "N\A") {
- alert("Please enter the basic details");
- return false;
- }
-
-
-
-
- if (partyname == "" || partyname == "null") {
- alert("Please enter the partyname ");
- return false;
- }
- if (address == "" || address == "null") {
- alert("Please enter the Address ");
- return false;
- }
- if (emailid != "" || emailid != "null") {
- var re = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
- var testEmail = re.test(emailid);
- if (!testEmail) {
- alert("Please enter a valid email!");
- return false;
- } else {
- $().SPServices({
- operation: "UpdateListItems",
- async: false,
- batchCmd: "New",
- listName: "Party_Master",
- valuepairs: [
- ["Party_x0020_Name", partyname],
- ["Address", address],
- ["Mobile_x0020_No", phonenumber],
- ["Contact_x0020_Person", contact],
- ["Email_x0020_ID", emailid],
- ["Case_x0020_Id", caseid]
- ],
- completefunc: function(xData, Status) {
- alert("Created new party");
- }
- });
- $("#partyname").val("");
- $("#address").val("");
- $("#phonenumber").val("");
- $("#contact").val("");
- $("#emailid").val("");
- }
- } else {
- alert("Please enter email address!");
- return false;
- }
- }
- Call this function through onclick event, using the button for Adding.
- <input class="popup_save" id="btn_addparty" type="button" value="Add Party" onclick="addparty();"/>
- Go to the site page and start filling in the details.
- Here the validation message for Email Id pops up, if entered wrong.
- Here is the outcome when a correct email Id entry is made and added through Add Party button.