WordPress Hosting
Free Photos
WordPress Themes

Check valid email for Yandex

# encoding: utf-8 require 'unirest' require 'nokogiri' # Malidator class Malidator # @param [String] email # @return [Malidator] def initialize(email) @email = email end # @return [Mixed] def valid? uri = 'https://passport.yandex.ru/registration-validations/login' headers = { x_requested_with: 'XMLHttpRequest' } parameters = { track_id: track_id, login: local_part } response = Unirest.post uri, headers: headers, parameters: parameters body = response.body !body.key? 'validation_errors' end private # @return [String] def local_part @email.split('@').first end # @return [String] def domain @email.split('@').last end # @return [String] def track_id response = Unirest.get 'https://passport.yandex.ru/registration' raw_body = response.raw_body doc = Nokogiri::HTML raw_body element = doc.at_css '[id="track_id"]' element.attribute('value').value end end
malidator = Malidator.new 'foo@yandex.ru'

return true if email address is valid (no error)
return false if email address is invalid (have error)

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.