简体   繁体   中英

Parsley.js validate functions without dom elements

I love using the parsely form validation helpers in instances where I have a form. But, I would love to be able to access the validation functions manually for instances where I just have a variable in some JS code that I'd like to validate. ie)

var someEmail = "hello@gmail.com";
parsely.isEmail(someEmail);

Now, I'm aware that this is a trivial example and there are tons of regex's available for me to create my own isEmail() function. But, if I'm already including parsely which has tons of built in validation functions it would be great to leverage them.

Does anyone know of a way to do this without having to create placeholder DOM elements on the fly like described here ?

不,没有(简单)的方法可以直接访问验证,但是验证“虚拟”输入非常容易,无需向DOM添加任何内容:

$('<input>').parsley({type: 'email'}).isValid(true, someEmail);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM