<form action = '#' method = 'post' onsubmit = "return checkForm( this )">
<input name='data'>
<input type='submit'>
</form>
<script type='text/javascript'>
function checkForm( theForm )
{
var result = /[^a-z0-9\\,\\.\\;]/g( theForm.data.value );
if( result )
{
alert('One or more illegal characters were found, the first being character ' + ( result.index + 1 ) + ' "' + result +'".\
\
Please edit your input.');
}
return !result;
}
</script>
One of them has uppercase A-Z as well, and has had added to it colon quote space.
The numbers in curly braces indicate the min/max characters that will be matched.
The ^ inside the square brackets indicates that those characters much not match
Whereas, the ^ at the start, with the $ at the end, indicates that what’s in-between must match the entire string.
<form action = '#' method = 'post' onsubmit = "return checkForm( this )">
<input name='data'>
<input type='submit'>
</form>
<script type='text/javascript'>
function checkForm( theForm )
{
var result = /^[a-zA-Z0-9\\.;,:' ]{1,100}$/g( theForm.data.value );
if( result )
{
alert('One or more illegal characters were found, the first being character ' + ( result.index + 1 ) + ' "' + result +'".\
\
Please edit your input.');
}
return !result;
}
</script>
I have run up a test of the code that was posted and it seems to work. What seems to be the problem?
Do you have any test inputs that are not working as expected?
Or is something more serious occurring. If so, something might be conflicting that we can resolve by taking a look.
It seems to work on the test code that I created from your post, so assuming that your test code is the same, there must be something else causing the problem.
Can you help me to take a look at your test page? Commonly the most effective way is for you to link to a test page that you have on the internet, or failing that, you can attach a file to a post.
By the way. The script will only run when scripting is actually enabled.
[list][]Does the form submit to a blank page?
[]Does the form submit to an error page?
[]Does the alert appear when it shouldn’t?
[]Does your computer explode at random?
[/list]
Can you please break this down in to steps that I can follow to try and duplicate your experience. For example:
[list][]what you enter
[]what you expect to occur
[*]the problem that actually occurs[/list]
From what I’m getting from you right now, I believe that you do not have scripting active on your web browser for this page.