1.4.0 • Published 6 years ago

@antnex2018/form-validation v1.4.0

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

form-validation

Build Status npm version npm Greenkeeper badge

Validate data fields format in JavaScript

Usage

npm i @yutangshi/form-validation --save
const formValidation = require('formValidation');
const form = new formValidation(); // Get the validation object

// Validate user name input. 驗證姓名不可為數字或特殊符號。
const res = form.userName("Allen");
// response format
// {
//	status: 200,
//	message: ""
// }

// Validate mobile input. 驗證手機號碼必須為09開頭且為10碼
const res = form.mobile("001399302");
// response format
// {
//	status: 512,
//	message: "您輸入的手機格式不正確。"
// }

// Validate email input. 驗證Email必須包含@符號以及.的網域名稱。
const res = form.email("service@com");
// response format
// {
//	status: 512,
//	message: "您輸入Email格式不正確。"
// }

// Validate identity card input of Taiwan. 驗證台灣身分證字號。
const res = form.idcard("11233211");
// response format
// {
//	status: 512,
//	message: "您輸入身分證字號格式不正確。"
// }


// Validate credit card input with customize message.
// 驗證信用卡16碼格資料格式,套用客製訊息。
const res = form.creditCard("11-2222-2345-2242","卡號不正確。");
// response format
// {
//	status: 512,
//	message: "卡號不正確。"
// }

// Validate number input with customize message.
// 驗證僅能輸入數字之資料格式,套用客製訊息。
const res = form.onlyNum("11222223452242","只能輸入數字。");
// response format
// {
//	status: 512,
//	message: "只能輸入數字。"
// }

// Validate chinese input with customize message.
// 驗證僅能輸入中文之資料格式,套用客製訊息。
const res = form.onlyChinese("測試","只能輸入中文。");
// response format
// {
//	status: 512,
//	message: "只能輸入中文。"
// }

// Validate letterAndNum input with customize message.
// 驗證僅能輸入英文字母與數字之資料格式,套用客製訊息。
const res = form.onlyLetterAndNum("Q123456789","只能輸入英文字母與數字。");
// response format
// {
//	status: 512,
//	message: "只能輸入英文字母與數字。"
// }

License

MIT