1.2.0 • Published 4 years ago

mgm-validation v1.2.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

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

  1. English-Name
  2. Name
  3. Name-With-Number
  4. Mobile
  5. Day
  6. Month
  7. Melli-Number
  8. Passport-Number
  9. Email

Props Available

mgm-validation component has the following props.

PropstypesdefaultDetail
labelString'نام'label of input text
setInputfuncsetValuecallback function for setting value
rtlDirectionbooleanfalsefor rtl data entry
typestring'Name'type of input --complete list mentioned above--
messageListobject--mentioned above--complete list of available error messages
nationalityString"Iran"uses for validation passport number
externalErrorbooleanfalseif none of the errors listed above happen in a component set this true
messageString''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