Working with incomplete information here…
Single input, multiple values. I do not understand why? There are so
many
resources available for you to permit users to enter multiple and
distinct
emails values.
The following is crude, but I think that it may be helpful…
Well as far as I know you can’t use
ActionView::Helpers::FormHelper :
email_field(object_name, method, options = {})
From the browser instance, you can introduce an onChange event on your
multiple value email field with JQuery/JavaScript:
making a call to something like (just offered as psuedo code):
var my_failed_email_address = Array // outside of the function, maybe
function validEmail(multiple_email_element_by_id)
var emailRegex =
/^[a-zA-Z0-9.!#$%&'+/=?^_`{|}~-]+@a-zA-Z0-9?(?:.a-zA-Z0-9?)$/;
/// Someone can probably suggest a better reg exp
Use Jquery to split the multiple_email_element_by_id field value
by
your required delimiter(s) and put it into an array…
var my_email_address = Array // Use the above to
populate
the array
For each element in resulting array
if (!( emailRegex.test(increment value) ) )
return true // maybe just return the empty array
else
my_failed_email_address.push(that element) //
Otherwise add new value to array
return false // maybe just return pupulated array
end
end
If this returns false, then you have numerous options: you can inform
the
user of failed email address(es) with an alert, populate some html
span/error associated with the email input with meaningful error
message,
or change the css on the email input…
Or you can use validation in the Controller or Model in a similar
fashion
In the Controller, parse the multiple email field from params and write
a
method to test for validity of each. If failure turn to originating
render
In the model, make accessible your multiple_email field, and write call
back to parse the field for validation. On failure, inform user at View
level with if model.errors.any?
Liz