ajax - jquery formvalidation engine add method -


how create method check if email valid, if validator find '@' sign? (the input text either name or email address only).

function checkmail(email){     var filter  = /^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/;     if (filter.test(email)) {         return true;     }     return false; }  checkmail('me@domain.com'); // return true or false if invalid. 

this check e-mailaddress additionally if valid domain written.

me@something --> invalid
@something.com --> invalid
me@.com --> invalid
me@something.com --> valid

regular expression library -->

if want validate mail address jquery validation engine, add:

data-validation-engine="validate[required,custom[email]]" 

to input field.


since form validation engine 1.6.4, there's possibility add own function validation: http://www.position-absolute.com/news/form-validation-engine-1-6-4/

you can replace code in example this, should work:

<input value="" data-validation-engine="validate[required,funccall[nameormail]]" class="text-input nameormail" type="text" name="req" id="req" /> 

js (to <head>):

jquery(document).ready(function(){     jquery("#formid").validationengine({         "nameormail": {             "nname":"nameormail"         }     }); });  function checkmail(email){     var filter  = /^([a-za-z0-9_\.\-])+\@(([a-za-z0-9\-])+\.)+([a-za-z0-9]{2,4})+$/;     if (filter.test(email)) {         return true;     }     return false; }  function nameormail(){     if($(".nameormail").val().indexof('@') >= 0){         if(!checkmail($(".nameormail").val())) {             return "please enter valid mail address or name!";         }     } else {         if($(".nameormail").val() === '') {             return "please enter valid mail address or name!";         }     } } 

live demo: http://jsfiddle.net/4duyx/


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -