Android Question Regex Pattern

khwarizmi

Active Member
Licensed User
Longtime User
Hi all

what does "[\d\w]+" in regex pattern means?
why does it give false when I wrote device name (+galaxy grand prime) in the edittext :

B4X:
If Regex.IsMatch("[\d\w]+", txtName.Text) = False Then
        ToastMessageShow("Name not valid", True)
        Return
    End If
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
wrong regex. ismatch() matches the whole string; that's not what you appear to want. use regex.matcher(), then if regex.matcher.find(). you seem to be looking to validate the input (ie, no garbage chars), not match the actual input, yes?

btw, "\d" is part of "\w". you don't need "\d". also, if your names can contain spaces, "\w" will fail. the space char is not part of "\w" (nor is the "+" char, but i wasn't sure if you were using it as some kind of test)
 
Upvote 0
Top