Jump to content
  • 0

Enforce the Submission Form to accept a decimal number with x.xxx format.


Azriel

Question

Hello,

Please help me, I have a submission form with a field that accepts value from 0.000 to 9.999.

I want to implement a validation that will prompt an error message, and will prevent the submission if the from x.xxx (ex:1.000, 3.321, etc..) is not followed.

Please help me, I have no Idea how to implement such validation.

Thank you in advance.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi  @Azriel,

I have a similar validation with my app, I've just edited it a bit so that it will meet your requirements. You can just add a header and footer in your submission form, then paste the code below in the footer section.  


<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function (event) {
event.preventDefault();

//Just change the 'InsertRecordNumber_' in the code below

var x = document.forms["caspioform"]["InsertRecordNumber_"].value;
  var regexp = /^\d+\.\d{3}$/;
  if (!regexp.test(x)) {
    alert("The correct GPA format should be x.xxx");
    return false;
  }

else
 {
document.getElementById("caspioform").submit();
 }


});
</script>

The only thing that you need to update in the code above is the actual ID of your field where you want to enforce this validation (Just replace the 'InsertRecordNumber_' in the code above)

image.thumb.png.4c1ae83c84f78345499db40023101c71.png

To get the ID of the field that you want to apply this validation, you can simply preview your DataPage or access the web page it is deployed and follow the instruction on this Link  to get the ID of your field.

I hope this helps.

Regards,

TsiBiRu

Link to comment
Share on other sites

  • 0

Just to add, if you also wish to validate value entered in an input field to make sure that it follows this format: www.websitename.com

Then you can use this code:

 


<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var inputField = document.querySelector('#InsertRecordNameofField');

  const value = inputField.value;
  const regex = /^www\.[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/;

if (!regex.test(value)) {
event.preventDefault();
alert('Invalid Submission!');

} else {

document.form["caspioform"].submit();

}

});
</script>

Make sure to replace "NameofField" with the actual name of the field that you want to validate before submitting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...