Module: ValidationsHelper
- Defined in:
- lib/watir_helper/validations_helper.rb
Instance Method Summary collapse
-
#contain_chars(char_set) ⇒ Object
Check whether the value entered contains a string or not.
-
#contains_sub_string(substring) ⇒ Object
Check whether a substring is present in a textfield or not.
-
#is_a_char(value) ⇒ Object
Check whether the value entered is a Character or not.
-
#is_a_Float(value) ⇒ Object
Check whether the value entered is a Float or not.
-
#is_a_reg_exp(value) ⇒ Object
Check whether the value entered is a Regular Expression or not.
-
#is_a_String(value) ⇒ Object
Check whether the value entered is a String or not.
-
#is_age_in_the_range(range_start, range_end) ⇒ Object
Check whether the age entered is in the given range or not.
-
#is_an_Integer(value) ⇒ Object
Check whether the value entered is an Integer or not.
-
#is_string_contains_character_set(char_string, char_set) ⇒ Object
Check whether a string contains another string or not.
-
#is_string_contains_reg_exp_character_set(char_string, char_set) ⇒ Object
Check whether a string contains a regular expression or not.
-
#validate_chars_range_contain_textfield(range_start, range_end) ⇒ Object
Check whether a character range is present in a textfield or not.
-
#validate_date_format_ddmmyyyy(date) ⇒ Object
Check whether a date is in ddmmyyyy format or not.
-
#validate_date_format_mmddyyyy(date) ⇒ Object
Check whether a date is in mmddyyyy format or not.
-
#validate_email_address(email_id) ⇒ Object
Check whether e-mail adress supplied is valid or not.
-
#validate_indian_landline_number(landline_no) ⇒ Object
Check whether the indian landline number entered is valid or not.
-
#validate_indian_mobile_number(mobile_no) ⇒ Object
Check whether the indian mobile number entered is valid or not.
Instance Method Details
#contain_chars(char_set) ⇒ Object
Check whether the value entered contains a string or not.
115 116 117 |
# File 'lib/watir_helper/validations_helper.rb', line 115 def contain_chars(char_set) is_string_contains_character_set($settext,char_set) end |
#contains_sub_string(substring) ⇒ Object
Check whether a substring is present in a textfield or not.
15 16 17 |
# File 'lib/watir_helper/validations_helper.rb', line 15 def contains_sub_string(substring) return $settext.sub(substring,'*').index('*') ? true : false end |
#is_a_char(value) ⇒ Object
Check whether the value entered is a Character or not.
110 111 112 |
# File 'lib/watir_helper/validations_helper.rb', line 110 def is_a_char(value) #Like "3",'3',"a",'a' value.length==1 end |
#is_a_Float(value) ⇒ Object
Check whether the value entered is a Float or not.
94 95 96 |
# File 'lib/watir_helper/validations_helper.rb', line 94 def is_a_Float(value) value.is_a?(Float) end |
#is_a_reg_exp(value) ⇒ Object
Check whether the value entered is a Regular Expression or not.
104 105 106 |
# File 'lib/watir_helper/validations_helper.rb', line 104 def is_a_reg_exp(value) value.is_a?(Regexp) end |
#is_a_String(value) ⇒ Object
Check whether the value entered is a String or not.
99 100 101 |
# File 'lib/watir_helper/validations_helper.rb', line 99 def is_a_String(value) value.is_a?(String) end |
#is_age_in_the_range(range_start, range_end) ⇒ Object
Check whether the age entered is in the given range or not.
38 39 40 41 42 43 44 |
# File 'lib/watir_helper/validations_helper.rb', line 38 def is_age_in_the_range(range_start,range_end) if ($settext.to_i>=range_start.to_i and $settext.to_i<=range_end.to_i) return true else return false end end |
#is_an_Integer(value) ⇒ Object
Check whether the value entered is an Integer or not.
89 90 91 |
# File 'lib/watir_helper/validations_helper.rb', line 89 def is_an_Integer(value) value.is_a?(Integer) end |
#is_string_contains_character_set(char_string, char_set) ⇒ Object
Check whether a string contains another string or not.
130 131 132 133 134 135 136 137 138 |
# File 'lib/watir_helper/validations_helper.rb', line 130 def is_string_contains_character_set(char_string,char_set) flag=0 #Here char_set is a string of characters char_set.each_byte do |char| if(char_string.sub(char.chr.to_s,'**').index('**') ? true : false )==true flag=1 end end flag==1 end |
#is_string_contains_reg_exp_character_set(char_string, char_set) ⇒ Object
Check whether a string contains a regular expression or not.
120 121 122 123 124 125 126 127 |
# File 'lib/watir_helper/validations_helper.rb', line 120 def is_string_contains_reg_exp_character_set(char_string,char_set) flag=0 #Here char_set is a regular expression of characters #The format for regular expression of character set(or char_set) should be like /[$#!@^*&()~]/ if(char_string.sub(char_set,'**').index('**') ? true : false)==true flag=1 end flag==1 end |
#validate_chars_range_contain_textfield(range_start, range_end) ⇒ Object
Check whether a character range is present in a textfield or not.
6 7 8 9 10 11 12 |
# File 'lib/watir_helper/validations_helper.rb', line 6 def validate_chars_range_contain_textfield(range_start,range_end) #for positive integers and chars range if (range_start <= range_end) and (range_start.length==1) and (range_end.length==1) puts $settext.gsub(/[#{range_start}-#{range_end}]/,'*').index('*')? "Present" : "Not Present" else puts "Error!!! :-Please input a valid range" end end |
#validate_date_format_ddmmyyyy(date) ⇒ Object
Check whether a date is in ddmmyyyy format or not.
29 30 31 32 33 34 35 |
# File 'lib/watir_helper/validations_helper.rb', line 29 def validate_date_format_ddmmyyyy(date) if(date=~/^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/).nil? puts "Invalid Date(ddmmyyyy) Format" else puts "Valid Date(ddmmyyyy) Format" end end |
#validate_date_format_mmddyyyy(date) ⇒ Object
Check whether a date is in mmddyyyy format or not.
20 21 22 23 24 25 26 |
# File 'lib/watir_helper/validations_helper.rb', line 20 def validate_date_format_mmddyyyy(date) if(date =~ /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/).nil? puts "Invalid Date(mmddyyyy) Format" else puts "Valid Date(mmddyyyy) Format" end end |
#validate_email_address(email_id) ⇒ Object
Check whether e-mail adress supplied is valid or not.
47 48 49 50 51 52 53 |
# File 'lib/watir_helper/validations_helper.rb', line 47 def validate_email_address(email_id) if(email_id=~/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/).nil? puts "Invalid E-mail id Format" else puts "Valid E-mail id Format" end end |
#validate_indian_landline_number(landline_no) ⇒ Object
Check whether the indian landline number entered is valid or not.
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/watir_helper/validations_helper.rb', line 75 def validate_indian_landline_number(landline_no)#like "020-30303030" if(landline_no.length==12) #In India landline number should be of 10 digits including std code #Here we will prefix "0" before std code and "-" between std code and the respective landline number if(landline_no=~/^[0]{1}[1-9]{1}[0-9]{1,3}[\-]{1}[1-9]{1}[0-9]{5,7}$/).nil? puts "Wrong Landline number format" else puts "Correct Landline number format" end else puts "Error!!!! :- Wrong Landline number format" end end |
#validate_indian_mobile_number(mobile_no) ⇒ Object
Check whether the indian mobile number entered is valid or not.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/watir_helper/validations_helper.rb', line 56 def validate_indian_mobile_number(mobile_no) if(mobile_no.to_i>0) if(mobile_no.length==10) if(mobile_no=~/^([9]{1})([023456789]{1})([0-9]{8})$/).nil? puts "Wrong Mobile number format" else puts "Correct Mobile number format" end elsif(mobile_no.length<10) puts "Error!!!! :- Mobile number length is less than 10 digit" elsif(mobile_no.length>10) puts "Error!!!! :- Mobile number length is more than 10 digit" end else puts "Error!!!! :- Mobile number can't be negative" end end |