non-4byte-chars-pattern
Version:
A pattern of HTML `input` element to restrict use of UTF-8 4-byte characters
54 lines (33 loc) • 1.82 kB
Markdown
# non-4byte-chars-pattern
[](https://www.npmjs.com/package/non-4byte-chars-pattern)
[](https://github.com/shinnn/non-4byte-chars-pattern/releases)
[](https://travis-ci.org/shinnn/non-4byte-chars-pattern)
[](https://coveralls.io/r/shinnn/non-4byte-chars-pattern)
[](https://david-dm.org/shinnn/non-4byte-chars-pattern)
[](https://david-dm.org/shinnn/non-4byte-chars-pattern?type=dev)
```javascript
import non4byteCharsPattern from 'non-4byte-chars-pattern';
const input = document.createElement('input');
input.setAttribute('pattern', non4byteCharsPattern);
input.value = 'Hello (^ ^)';
input.validity.patternMismatch; //=> false
input.value = 'Hello 🤗';
input.validity.patternMismatch; //=> true
```
## Installation
### [npm](https://www.npmjs.com/)
```
npm install non-4byte-chars-pattern
```
### [bower](https://bower.io/)
```
bower install non-4byte-chars-pattern
```
## API
### non4byteCharsPattern
Type: `String`
Note that this pattern regards an empty string `''` as valid. If you want to disallow blank input, use `required` attribute instead.
## Related project
[non-4byte-chars-regex](https://github.com/shinnn/non-4byte-chars-regex) - [`RegExp`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/RegExp) version of this module
## License
[The Unlicense](./LICENSE).