Dim eAddress As String
Dim Suf As String :Suf=".net" 'or .com or dot whatever
'BELOW TO VERIFY IF EMAIL ADDRESS IS VALID
eAddress="[email protected]"
If eAddress.Contains("@") AND eAddress.EndsWith(Suf) Then
Msgbox("Valid email: " & eAddress,"")
Else
Msgbox("Not a valid email address.","")
End If
Would this work for you or is it too simplistic:
B4X:Dim eAddress As String Dim Suf As String :Suf=".net" 'or .com or dot whatever 'BELOW TO VERIFY IF EMAIL ADDRESS IS VALID eAddress="[email protected]" If eAddress.Contains("@") AND eAddress.EndsWith(Suf) Then Msgbox("Valid email: " & eAddress,"") Else Msgbox("Not a valid email address.","") End If
RegEx
In PHP I use a string like '/^[_a-z0-9!#$%&~\{\}\-]{1,64}(\.[_a-z0-9!#$%&~\{\}\-]{1,64})*@[_a-z0-9\-]{1,63}(\.[_a-z0-9\-]{1,63})*(\.[a-z]{2,6})$/i'
I haven't tried converting it to work in B4A yet, but it works well in PHP.
'BELOW TO CHECK IF A STRING IS AN EMAIL ADDRESS
Dim eAddress As String
Dim eMatch As Matcher
eAddress="[email protected]"
eMatch = Regex.Matcher("\w+@\w+\.\w+", eAddress)
If eMatch.Find = True Then
Msgbox(eAddress & " is a valid email address","")
Else
Msgbox( eAddress & " is not a valid email address.","")
End If
Dim Valid As Boolean
Valid = Regex.IsMatch("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", "[email protected]")
If Valid Then
Msgbox("Valid Email Address", "")
Else
Msgbox("Invalid Email Address", "")
End If
I use this it work almost as o want:sign0098:Sorry Barry. I do not know php, but here is another sophisticated way to check if a string is an email address. It is a little fancier than the first one I put in the previous post:
B4X:'BELOW TO CHECK IF A STRING IS AN EMAIL ADDRESS Dim eAddress As String Dim eMatch As Matcher eAddress="[email protected]" eMatch = Regex.Matcher("\w+@\w+\.\w+", eAddress) If eMatch.Find = True Then Msgbox(eAddress & " is a valid email address","") Else Msgbox( eAddress & " is not a valid email address.","") End If
"[...] experts believe that Chinese registrars in China and Taiwan will quickly implement the change for internationalised email. Representatives of CNIC and TWNIC are authors of the standards. Chinese users currently have to write emails in ASCII to the left of the @ and in Chinese characters to the right of it for Chinese domains, which have already been internationalized."
Yes, it is an alien language and while most languages keep pretty much to the standards there are differences. To translate it a bit-
'/^[_a-z0-9!#$%&~\{\}\-]{1,64}(\.[_a-z0-9!#$%&~\{\}\-]{1,64})*@[_a-z0-9\-]{1,63}(\.[_a-z0-9\-]{1,63})*(\.[a-z]{2,6})$/i'
The / at beginning and ends just sort of mark the string like quotes around a string variable.
The i at the end ignores character case (upper/lower).
The ^ represents the beginning of the string and $ the end, so all that they send must meet the format
(if just ^ was used it would mean what they give starts with the format, etc).
The [] areas represent chars and char ranges in that section of the format string with some special chars needing \ escaped.
The {min, max} sections show how many characters from that group.
The () just group sections further and sometimes can have other meaning or allow modifying a found group/section later.
The () sections here are just used to further specify a count with the * which is 0 or more occurrences since not all emails contain a dot, but it is allowed.
I used to have the last part of the string as (\.[a-z]{2,3}) which was for the top level domains like .net, .com, .edu, .au, .de, etc.
There are some crazy domains lately though that can be up to like 11 chars, but I allowed for 2-6 in length to get the ones I care about and not leave it so open.
The problem is NOT to the .hp.com domain name but to the UCASE H and P of the mailbox name!Hello!
The code is almost perfect, but when there are multiple parties domains, validation is not correct.
For example for email <[email protected]> the result is not correct.