Jump to content

How to limit a form to not submit numeric


Recommended Posts

Hi @Perzival

You will need to use JavaScript to check the input then.  Use a document selector to get the input element and then check its value attribute. Make sure it is the right length. Then match it against a regular expression. (Learn about them here: Regular Expressions) If everything thing is fine, return true. Otherwise, return false

Link to comment
Share on other sites

9 minutes ago, Harbinger said:

Hi @Perzival

You will need to use JavaScript to check the input then.  Use a document selector to get the input element and then check its value attribute. Make sure it is the right length. Then match it against a regular expression. (Learn about them here: Regular Expressions) If everything thing is fine, return true. Otherwise, return false

This helps, but I am not fluent in JS, perhaps you can give me an idea on how to integrate regular expression with my form?

Link to comment
Share on other sites

25 minutes ago, Perzival said:

This helps, but I am not fluent in JS, perhaps you can give me an idea on how to integrate regular expression with my form?

Try this:

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

var x = document.getElementById('InsertRecordDOM').value;
     if (typeof x === 'number' || (x%1===0)) {
alert('This form only submit alpha characters!');

} else {

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

}

});
</script>

Link to comment
Share on other sites

46 minutes ago, Harbinger said:

Try this:

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

var x = document.getElementById('InsertRecordDOM').value;
     if (typeof x === 'number' || (x%1===0)) {
alert('This form only submit alpha characters!');

} else {

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

}

});
</script>

Exactly what I need.. Thank you!

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
Reply to this topic...

×   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...
 Share

×
×
  • Create New...