1.2.0 • Published 4 years ago
mgm-validation v1.2.0
React text input field validation
This package will validate these items : 1. Email 2. Name ( not supported numbers) 3. Passport Number 4. Melli Code number 5. Mobile 6. Day Range 7. Month Range
Installation 🚀
Using NPM:
npm i mgm-validation
Using yarn
yarn add mgm-validation
Usage:
const errorMessagesMock = {
onlyNumer : 'تنها ورود عدد مجاز است';
onlyLetter : 'تنها ورود حرف مجاز است';
onlyLatinLetter : 'تنها ورود حرف لاتین مجاز است';
notSupportedChar : 'کاراکتر غیرمجاز وارد شده است';
mobileFormat : 'فرمت موبایل صحیح نمی باشد';
dateRange : 'بازه زمانی صحیح نمی باشد';
melliNumberFormat : 'فرمت کد ملی صحیح نمی باشد';
passportNumberFormat : 'فرمت شماره پاسپورت صحیح نمی باشد';
emailFormat : 'فرمت ایمیل صحیح نمی باشد';
}
const [mobile, setMobile] = useState(0);
const [name, setName] = useState('');
const setValue = (data, type) => {
if (type === 'name') {
setName(data);
}
else {
setMobile(data)
}
}
return (
<div>
<CustomInput
label='موبایل'
setInput={e => setValue(e, 'mobile')}
rtlDirection={false}
type='Mobile'
messageList={errorMessagesMock}
/>
<CustomInput
label='نام'
setInput={e => setValue(e, 'name')}
rtlDirection={true}
type='Name'
messageList={errorMessagesMock}
/>
</div>
);
Types of CustomInput
- English-Name
- Name
- Name-With-Number
- Mobile
- Day
- Month
- Melli-Number
- Passport-Number
Props Available
mgm-validation component has the following props.
Props | types | default | Detail |
---|---|---|---|
label | String | 'نام' | label of input text |
setInput | func | setValue | callback function for setting value |
rtlDirection | boolean | false | for rtl data entry |
type | string | 'Name' | type of input --complete list mentioned above-- |
messageList | object | --mentioned above-- | complete list of available error messages |
nationality | String | "Iran" | uses for validation passport number |
externalError | boolean | false | if none of the errors listed above happen in a component set this true |
message | String | '' | custom error text ccording to externalError |
1.2.0
4 years ago
1.1.9
4 years ago
1.1.8
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.5
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.9
4 years ago
1.0.2
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago