named for my mentor of javascript -- huangyi
better-validation is a plugin that collect some useful validation,such as "is this string a legal email address?" you can easily use this and expand your validation through API.
Just easily import it.
<script src="path/to/better-validation.js"></script>
<script>
BValidation.isEmail('2@2.com');//true
BValidation.isValidDate('2017-02-29');//false
//expand
BValidation.install('myValidation', function(param){
return !isNaN(param);
});
//use it
BValidation.myValidation('some thing');//false
</script>
Or import like this.
//some code
import BValidation from 'better-validation';
BValidation.isEmail('abc@sina.com');//true
### API
```javascript
BValidation.isNumber(param)
check if the type of param is number.
BValidation.isEmail(param)
check if the param is legal email account.
BValidation.isValidAccount(param)
check if the param is legal user account.
the rule is :
length between 4 and 16 included.
letter,number,_,- is required.
BValidation.isUrl(param)
check if the param is legal http,https,ftp or file url.
BValidation.isChnPostcode(param)
check if the param is legal chinese postcode.
BValidation.isTel(param)
check if the param is legal chinese telphone number.
these are allowed:
(021)-12345678
021-12345678
1234567
12345678
BValidation.isMobile(param)
check if the param is legal mobile phone number.
BValidation.isIDCardNo15(param)
check if the param is legal chinese ID card number,which length is 15.
BValidation.isIDCardNo18(param)
check if the param is legal chinese ID card number,which length is 15.
BValidation.isValidPassword(param)
check if the param is legal user password.
the rule is :
length between 6 and 18 included.
letter,number,_ is required
BValidation.isChineseOnly(param)
check if the param contains chinese character only.
BValidation.isChineseContains(param)
check if the param contains chinese character.
BValidation.isHexColor(param)
check if the param is hex color.
BValidation.isQQ(param)
check if the param is legal QQ number.
BValidation.isWX(param)
check if the param is legal WeiXin number.
BValidation.isCarNo(param)
check if the param is legal card number in China.
BValidation.isValidDate(param)
check if the param is legal date.
Such as '2017-02-01' is correct.
'2017-02-29' is incorrect.
BValidation.isIPv4(param)
check if the param is legal IPv4 address.
BValidation.install('name',function)
you can expand the validation through this function.
BValidation.install('myValidation', function(param){
return !isNaN(param);
});
BValidation.myValidation('lol')//false