Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
shahumang8
Posts: 671
Registered: ‎08-09-2010
My Device: Not Specified

Email validation into TextField

[ Edited ]

Hello,

 

      Any idea how to validate email in TextField?

 

     

.

Contributor
raspberry1
Posts: 16
Registered: ‎05-26-2013
My Device: Z10

Re: Email validation into TextField

Hi,

 

 Have you figured out how to  validate an email?

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Email validation into TextField

you can compare the old text and the new text using a regular expression. if the result is false, replace the new with the old text.
I do that in Qt, but it should also be available in QML, see
http://supportforums.blackberry.com/t5/Cascades-Development/textfield-textarea-input-masking/td-p/24...
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
hemant_sain
Posts: 180
Registered: ‎12-09-2011
My Device: 9360, BB10

Re: Email validation into TextField

Try this may be it will help you..

 

function validEmail(emailId) {
var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (emailId.length > 0 && reg.test(emailId)) {
return true;
}
return false;
}

Retired
PBernhardt
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30

Re: Email validation into TextField

Validating emails is actually super complex, and most regular expressions are too restrictive. For example, having example+somestuff@somedomain.com is a vaild address that is often rejected.

 

http://davidcel.is/blog/2012/09/06/stop-validating-email-addresses-with-regex/

 

Honestly, something simple like just making sure it has an @ symbol in it is probably enough. How valid do you really need it to be? At the end of the day, only way you can really be sure it's correct is to send an email to that address.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker