Jump to content
  • 0

how to disallow special characters in forms


dreamydesigner
 Share

Question

4 answers to this question

Recommended Posts

  • 0

Hi!

Just wanted to share my solution with you. If you would like to have an alert, you can use this script in the Footer of the DataPage:

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

event.preventDefault();

	var username = document.getElementById("InsertRecordFIELDNAME").value;
	var inputRGEX = /^[a-zA-Z0-9 ]*$/;
	var inputResult = inputRGEX.test(username);

	if(!(inputResult))
	{
		alert("Please only use standard alphanumerics");
	}
	else 
	{
		document.forms["caspioform"].submit();
	}
});

</script>

Please note to replace the FIELDNAME in the JavaScript with name of the field.

Link to comment
Share on other sites

  • 0

You may also try this:

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function (e) {
  
	var username = document.getElementById("InsertRecordFIELDNAME").value;
	var inputRGEX = /^[a-zA-Z0-9 ]*$/;
	var inputResult = inputRGEX.test(username);

	if(!(inputResult))
	{
		e.preventDefault();
		alert("Please only use standard alphanumerics");
        
	}
});

</script>
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...
 Share

×
×
  • Create New...