0.2.8 • Published 7 months ago

@thunder_fury/form-validate v0.2.8

Weekly downloads
51
License
MIT
Repository
github
Last release
7 months ago

@thunder_fury/from-validate

Installation

  $ npm i -D @thunder_fruy/from-validate

import

import { Validate } from '@thunder_fury/form-validate';
const { Validate } = require('@thunder_fury/form-validate');

Method

MethodreturnDescription
Validate.check({value, labelName, validateTypes }) {isError, errorMessage} You can specify strings for input element and field name resolution types as parameters. An error exists and returns an error message as an object.

validate key type

validate methodDescription
requiredCheck if there is a value
enEnglish Type check
emailEmmail Type check
numberNumber Type check
maxLength:numstring max length check
minLength:numstring min length check
maxNumber:nummax number check
minNumber:nummin number check

customize Error message

  • You can customize the message by setting the message in the validation method key.
  • {maxLength}・{minLength}・{maxNumber}・{minNumber} The set number is returned, and {labelName} is the field passed by the user.
## default Messages
  required: '{labelName} field is required。',
  en: '{labelName} field can only contain English characters.',
  email: 'Please enter a valid {labelName} address.',
  number: '{labelName} field can only contain numbers.',
  maxLength: '{labelName} field must be {maxLength} characters or less.',
  minLength: '{labelName} field must be at least {minLength} characters.',
  maxNumber: '{labelName} must be {maxNumber} or less.',
  minNumber: '{labelName} must be {minNumber} or more.'
  • Example of error message setting in Korean
Validate.message = {
  required: '{labelName}필드는 필수 항목입니다',
  maxLength:'{labelName}필드는 {maxLength}글자 이하로 입력해주세요',
  min:'{labelName}필드는 {min}이상 입력해주세요',
  // ... skip ...
}
  • Example of error message setting in Japanese
Validate.message = {
  required: '{name}項目は必須です。',
  maxLength:'{name}は{maxLength}文字以下で入力してください',
  minNumber:'{name}は{minNumber}以上入力してください',
  // ... skip ...
}

Example of use

The code below is an example usage. First you need to set the arguments to pass to the Validate method. If the input type is verified and an error is returned for that type, an error message is displayed.

request

const result = Validate.check({'val', 'labelName', 'minLength:3 maxLength:5 required' });

response

return {
  errorMessage: "name field must be at least 3 characters."
  isError: true
}
0.2.7

7 months ago

0.2.6

7 months ago

0.2.8

7 months ago

0.2.5

7 months ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.2

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago