jQuery(function(){
jQuery('.ValidField').each(function(){
jQuery(this).validate({
expression: "if (VAL) return true; else return false;",
message: "Please enter the Required field"
});
});
jQuery('.ValidInteger').each(function(){
jQuery(this).validate({
expression: "if (VAL.match(/^[0-9]*$/) && VAL) return true; else return
false;",
message: "Please enter a valid numeric value"
});
});
jQuery(".ValidDropdown").each(function(){
jQuery(this).validate({
expression: "if (VAL != '') return true; else return false;",
message: "Please make a selection"
});
});
//put * on valid fields
//jQuery('.ValidField').prev().prev().after('*').css('color','#FF0000');
//prev prev => <label>
jQuery('.ValidField, .ValidInteger, .RequiredField,
.ValidDropdown,.ValidEmail').prev().prev().after('*');
// for valid emails fields
jQuery(".ValidEmail").each(function(){
jQuery(this).validate({
expression: "if
(VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/))
return true; else return false;",
message: "Please enter a valid Email ID"
});
});
//for valid date format
jQuery(".ValidDate").each(function(){
jQuery(this).validate({
expression: "if (!isValidDate(parseInt(VAL.split('-')[2]),
parseInt(VAL.split('-')[0]), parseInt(VAL.split('-')[1]))) return false;
else return true;",
message: "Please enter a valid Date"
});
});
});add this jquery in application.js in app/assests/javascript/application.js and add javascript.validation.js in javascript which i am sending to as an attachment.hope this will working for you. On Tue, Mar 6, 2012 at 12:29 AM, Dev Guy <[email protected]> wrote: > On Mon, Mar 5, 2012 at 7:14 AM, Mohamad El-Husseini > <[email protected]> wrote: > > Have you seen > > this? http://railscasts.com/episodes/263-client-side-validations > > > > > > On Sunday, March 4, 2012 7:08:34 PM UTC-3, Rajinder Yadav wrote: > >> > >> Hi I know with javascript we can validate the input of a form on the > >> client, is there an easy way to specify this in rails? I am thinking > >> the javascript code getting generated using some sort of DSL? > >> > > Hi Mohamad, thanks I will take a look at this! > > -- > Kind Regards, > Rajinder Yadav > > SafetyNet Test Driven Development > http://safetynet.devmentor.org > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
jquery.validate.js
Description: JavaScript source

