You are missing start and end anchor tag so you can refer this link Regular expressions with validations in RoR 4 and your correct regex will be,
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
You should try this regex also for email validation, this regex will fulfill your all requirement and checking all the required possible validation.
^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
and Here is explanation of regex which will be useful for understanding validation
^ #start of the line
[_A-Za-z0-9-\\+]+ # must start with string in the bracket [ ], must contains one or more (+)
( # start of group #1
\\.[_A-Za-z0-9-]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #1, this group is optional (*)
@ # must contains a "@" symbol
[A-Za-z0-9-]+ # follow by string in the bracket [ ], must contains one or more (+)
( # start of group #2 - first level TLD checking
\\.[A-Za-z0-9]+ # follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* # end of group #2, this group is optional (*)
( # start of group #3 - second level TLD checking
\\.[A-Za-z]{2,} # follow by a dot "." and string in the bracket [ ], with minimum length of 2
) # end of group #3
$ #end of the line
Tested output:
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : [email protected] , true
Email is valid : abc , false
Email is valid : [email protected] , false
Email is valid : [email protected] , false
Email is valid : [email protected] , false
Email is valid : [email protected] , false
Email is valid : [email protected] , false
Email is valid : abc()*@gmail.com , false
Email is valid : abc@%*.com , false
Email is valid : [email protected] , false
Email is valid : [email protected] , false
Email is valid : abc@[email protected] , false
Email is valid : ab [email protected] , false
Email is valid : [email protected] , false