Send this to a friend
1 validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
2
3
4
5
6
7
8
9
10
11
12
13
validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
Send this to a friend
1 validates :price, :presence => true, :format => { :with => /[0-9\,]*/ }
validates :price, :presence => true, :format => { :with => /[0-9\,]*/ }
Send this to a friend
1 validates_format_of :email,
2 :with => /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/,
3 :message => "is invalid"
validates_format_of :email,
:with => /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/,
:message => "is invalid"
Send this to a friend
create your javascript validate function and call in your form
1 <% form_tag "/login", :onsubmit => 'return validate(this)' do %>
2
3 <% end %>
4
5
6
7 <% form_remote_tag :url => "/login", :update => 'temp', :before => 'if( !validate(this) ) return false' do %>
8
9 <% end %>
<% form_tag "/login", :onsubmit => 'return validate(this)' do %>
<% end %>
<% form_remote_tag :url => "/login", :update => 'temp', :before => 'if( !validate(this) ) return false' do %>
<% end %>
Send this to a friend
requires prototype and script.aculo.us
demo: http://ajaxorized.com/examples/scriptaculous/email.html
1 var isValid = false;
2
3 validateEmail = function(e) {
4 if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
5 if(!isValid) {
6 $(e).morph('border-color:#00FF00', {duration:.3});
7 isValid = true;
8 }
9 } else {
10 if(isValid) {
11 $(e).morph('border-color:#FF0000', {duration:.3});
12 isValid = false;
13 }
14 }
15 }
16
17
var isValid = false;
validateEmail = function(e) {
if(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/.test(e.value)) {
if(!isValid) {
$(e).morph('border-color:#00FF00', {duration:.3});
isValid = true;
}
} else {
if(isValid) {
$(e).morph('border-color:#FF0000', {duration:.3});
isValid = false;
}
}
}
Send this to a friend
1 validates_format_of :company_url, :with => /((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?)/
2 validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create, :message=>"has an invalid format"
3 validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => 'email must be valid'
4 validates_format_of :login, :with => /\w+@\w+\.\w{2}/
5
validates_format_of :company_url, :with => /((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?)/
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :on => :create, :message=>"has an invalid format"
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i, :message => 'email must be valid'
validates_format_of :login, :with => /\w+@\w+\.\w{2}/