npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

formcheck

v1.0.0

Published

表单验证插件

Downloads

3

Readme

formcheck

一个表单验证的js插件,不依赖任何框架

安装

npm 的方式
npm install formcheck --save
或
cnpm insatll formcheck --save

支持CDN引入
git地址:https://github.com/cttaohua/formcheck
下载下来后引入dist文件夹下得formcheck.js
<script src="./dist/formcheck.js"></script>

使用

  • 在main.js中添加
import formcheck from 'formcheck'
  • 在html中使用
<form id="myForm">
	<input type="text" ck ck-type="empty" ck-alert="请输入地址"></br>
	<input type="number" ck ck-type="phone"></br>
	<input type="text" ck ck-type="email"></br>
	<input type="text" ck ck-match="/^[0-9]+.?[0-9]*$/" ck-alert="请输入正确的数字"></br>
	<input id="submit" type="button" value="提交">
</form>
  • 在js中使用 1、在需要验证的input上加ck 2、需要定义判断的类型,如ck-type="phone",就按手机号处理,未定义则按必填字段处理 3、可以自定义提示语句,ck-alert="[自定义]",未定义formcheck会有默认的提示,见下方 4、也可以直接传入一个正则匹配,ck-match="/^[0-9]+.?[0-9]*$/"
var submit = document.getElementById('submit');
			
submit.addEventListener('click',function(){
	var res = checkForm({
		el: 'myForm'
	})
	if(!res.result) {
		alert(res.info);
	}else {
		//todo
	}
})

调用formcheck会返回一个对象,其中包括两个属性 1、result result为true表示表单验证通过,为false表示有的项验证不通过 2、info info返回的是需要提示的信息checkform会有一些默认提示

示例:{result: false, info: "请输入正确的手机号"}

  • 目前支持的类型
{
    phone: 'phone',    //电话号
    number: 'number',  //数字
    empty: 'empty',    //必填
    email: 'email'     //邮箱
}
  • formcheck默认设定的提示语
{
    phone: '请输入正确的手机号',
    number: '请输入有效的数字',
    empty: '此字段不能为空',
    email: '请输入正确的邮箱'
}