you are in: codestackercodes [RSS] → tag: validation [RSS]

rails 3 validates method Delicious Email

show/hide lines
   1  validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }
   2  
   3  # :presence => true
   4  # :uniqueness => true
   5  # :numericality => true
   6  # :length => { :minimum => 0, maximum => 2000 }
   7  # :format => { :with => /.*/ }
   8  # :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } # email format
   9  # :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix } # url format
  10  # :inclusion => { :in => [1,2,3] }
  11  # :exclusion => { :in => [1,2,3] }
  12  # :acceptance => true
  13  # :confirmation => true
created by leozera — 05 June 2011 — get a short url — tags: rails ruby validation embed

rails 3 money validation Delicious Email

show/hide lines
   1  validates :price, :presence => true, :format => { :with => /[0-9\,]*/ }
created by leozera — 04 June 2011 — get a short url — tags: ruby validation embed

email regex Delicious Email

show/hide lines
   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" 
created by leozera — 21 June 2009 — get a short url — tags: rails validation embed

validation client-side with form_tag and form_remote_tag Delicious Email

create your javascript validate function and call in your form

show/hide lines
   1  <% form_tag "/login", :onsubmit => 'return validate(this)' do %>
   2      <!-- your form -->
   3  <% end %>
   4  
   5  <!-- or -->
   6  
   7  <% form_remote_tag :url => "/login", :update => 'temp', :before => 'if( !validate(this) ) return false' do %>
   8      <!-- your form -->
   9  <% end %>
created by leozera — 30 November 2008 — get a short url — tags: form_remote rails validation embed

realtime email validation Delicious Email

requires prototype and script.aculo.us
demo: http://ajaxorized.com/examples/scriptaculous/email.html

show/hide lines
   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  // <input type = "email" id = "myinput" onKeyUp = "validateEmail(this)" />
created by leozera — 22 November 2008 — get a short url — tags: javascript prototype scriptaculous validation embed

validation sample Delicious Email

show/hide lines
   1  validates_format_of :company_url, :with => /((http|https):\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?)/ # valida URL
   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  
created by anonymous — 17 June 2008 — get a short url — tags: rails regex validation embed