phonenumber-format
v1.0.2
Published
Format phone numbers: 123-456-7890. Validates numbers only and min-max length
Downloads
10
Maintainers
Readme
Phonenumber-Format for ReactJS
Format a telephone number 123-345-67890.
This is a simple package that provides the format 123-345-67890 to a telephone number.
It includes:
- Validates that input is numbers only (or dashes, as it automatically adds them).
- It has maximum length. (13 characters counting the 10 digits and 2 dashes).
Usage
- npm install phonenumber-format --save
- Import FormatPhoneNumber from 'format-phone-number';
- Provide props: "onChange" (function) and "value" (string).
- You can pass it a className string and provide any input style.
Example
import React from 'react';
import FormatPhonenumber from 'format-phonenumber';
class AppComponent extends React.Component {
constructor (props) {
super(props);
this.state = {
phoneNumber : '',
};
}
render() {
return (
<div>
<FormatPhonenumber
className="input-formatter"
onChange={this.handleChange} value={this.state.phoneNumber}
/>
</div>
);
}
handleChange = (value) => {
this.setState({
phoneNumber : value
})
}
}
export default AppComponent;
License
MIT