- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2019 04:10 AM
Hi all, I have a requirement
could you please advise, I want to stop the users from entering special character in, field on a ui page.
So, the table below shows the characters we should allow, anything else should not be allowed.
Thanks In advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2019 06:34 AM
Using the following regular expression globally should capture anything that is not in listed in your screenshot:
var regexp = /[^\u0000-\u007F]|[\||{|}|`|~]/;
Note the caret '^' when used inside brackets '[]' takes on a negation as opposed to when it's used outside of the brackets. Which then it means the start of the string. Also I used a unicode range here to capture the basic latin characters which includes numbers.
So the above loosely means flag me if any character is NOT between the given unicode characters OR if it's a pipe "|", open curly "{", close curly "}", back tick "`", or tilde "~". Regular expression reference
Here is a basic example using an input:
<input id="test" onkeyup="doCheck(this)">
<script>
var t = document.getElementById("test");
var regexp = /[^\u0000-\u007F]|[\||{|}|`|~]/;
function doCheck(evt){
var val = evt.value.match(regexp);
if(val){
alert("illegal character: '" + val[0] + "'")
}
}
</script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2019 04:43 AM
Hi JMR
Create function eg. functionName() in Client controller which returns true if your condition satisfied.
then
<form action="" onsubmit="return functionName();">
If my answer helped you in any way, please then mark it correct and helpful.
Kind regards,
Manas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2019 05:20 AM
This Community post should give you a good direction in creating your validation script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-13-2019 06:34 AM
Using the following regular expression globally should capture anything that is not in listed in your screenshot:
var regexp = /[^\u0000-\u007F]|[\||{|}|`|~]/;
Note the caret '^' when used inside brackets '[]' takes on a negation as opposed to when it's used outside of the brackets. Which then it means the start of the string. Also I used a unicode range here to capture the basic latin characters which includes numbers.
So the above loosely means flag me if any character is NOT between the given unicode characters OR if it's a pipe "|", open curly "{", close curly "}", back tick "`", or tilde "~". Regular expression reference
Here is a basic example using an input:
<input id="test" onkeyup="doCheck(this)">
<script>
var t = document.getElementById("test");
var regexp = /[^\u0000-\u007F]|[\||{|}|`|~]/;
function doCheck(evt){
var val = evt.value.match(regexp);
if(val){
alert("illegal character: '" + val[0] + "'")
}
}
</script>