Reputation: 71
How can i allow only "A-Za-z0-9 &#$._-" along with "/" . I tried with jquery
$('.allow').bind('keyup blur',function(){
$(this).val( $(this).val().replace(/[^A-Za-z0-9 &#$._-]/g,' ') ); }
);
Along with this i also need to allow forward slash "/".
Can anyone please help me out. It will be a great help.
Upvotes: 2
Views: 113
Reputation: 3320
$('.allow').bind('keyup blur',function(){
$(this).val( $(this).val().replace(/[^A-Za-z0-9\\ &#$._-]/g,' ') ); }
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" class="allow"/>
Upvotes: 0
Reputation: 87203
Use ^
and $
outside of []
. This will match only the allowed characters.
You need to escape the /
and -
in regex
/^[a-z0-9 &#$._\-\/]$/i
Upvotes: 2