Restrict JS useful when you want to prevent or allow certain character for the input fields. For example the phone number field you maybe want to allow people to insert numeric only or numeric with plus.
When you use Restrict JS, when you copy and paste something into the input text, it will not allowed.
By default, all the keyboard buttons are allow
backspace
delete
shift
left arrow
right arrow
up arrow
down arrow
IE / Edge |
Firefox |
Chrome |
Safari |
iOS Safari |
Samsung |
Opera |
---|---|---|---|---|---|---|
IE9++, Edge |
NPM
npm install --save restrict-js
Yarn
yarn add restrict-js
import 'restrict-js'
or
<script src="restrict-js.min.js"></script>
Add data-restrict-js
at your input field. For example you want to accept only alpha numeric. You can set the value as alphanumeric
data-restrict-js="alphanumeric"
<input id="phone_number" name="phone_number" type="text" class="form-control" data-restrict-js="numeric">
alpha - Only allow alphabet. A-Z
numeric - Only allow numeric. 0-9
alphanumeric - Only allow alphabet numeric. A-Z,0-9
alphaspace - Only allow alphabet and space.
alphadash - Only allow alphabet and dash (-)
email - Only allow alphabet, numeric, @ (alias), . (dot), - (hypen), _ (underscore)
url - Only allow alphabet, numeric, : (colon), . (dot), / (forward slash)