How to deny all symbols but allow - and / and

Hello, how to deny all symbols but allow - and / and . ?

I have this Jquery: (allows numbers and alphabetic only)

<script>
	$(document).ready(function(){
		$('#id').bind('keyup',function(){
			$(this).val($(this).val().replace(/[^0-9a-z ]/gi, ""));
		});
	});
</script>
<input type="text" id="id">

Here are the fiddle: https://jsfiddle.net/master1991/zqkv8u1L/

Who can help?
Thanks in advance!

You would add those allowed symbols to the existing character class.

I forgot to mention that i m completely bad with Regex :frowning: Have no idea what i need edit in it!

What’s prefix?

Sorry i ment Regex

With regex, a character class is surrounded with square brackets.
In a character class, the hyphen has a special meaning, to indicate a range of letters or numbers.
You can still add a hyphen to a character class, but should escape it by prefixing it with a slash, like \-

The forward slash also has special meaning, so you should escape that too, with \/

The question mark can just go in the character class without needing to do anything special to it.

I do not get it: $(this).val($(this).val().replace(/[^0-9a-z ][\-\]/gi, ""));
now all charaters work i m lost here :smiley:

Don’t put them into a different set of square brackets, put them in to the same set of square brackets that contain your numbers and letters.

I am not going to give you the code that you need. That’s up to you to do, based on you understanding what I’m telling you.

1 Like

He he: like this: (this).val((this).val().replace(/[^0-9a-z -./]/gi, “”));

Thanks Master!

1 Like