iamtryingtocheckwhetherapasswordisalphanumericornotusingregex
butiamnotgettingtheresultiexpect.whatistheproblemwiththebelowcode?
booleanpasswordonlyalphanumericcheck=false;
patternpatternalphanumericcheck=pattern.com pile (' pgddlca-za-z0-9 ) $ ' );
matchermatcheralphanumericcheck=patternalphanumericcheck.matcher (log in.get password () );
if (matcheralphanumericcheck.find ()
passwordonlyalphanumericcheck=true;
Thanks for help
youneedtoaddaquantifierthatsuitsyourrequirements : *-0 ormoreoccurrencesor-1 ormoreoccurrences.youcanalsoomitthe ^ and
booleanpasswordonlyalphanumericcheck=false;
if(login.getpassword ().matches([a-za-Z0-9]* ) )
passwordonlyalphanumericcheck=true;
To match all Unicode letters,usep{l}class(andperhaps,p{M} to match diacritics ) 3360((p{l}p )
whatisthedifferencebetweenlogin.get password ().Matches ) ' [0-9a-za-z]* '; and login.getPassword ().matches([0-9a-za-z] );
the.Matches([0-9a-za-z] ) willonlyreturntrueifthewholestringcontainsjust1digitor letter.the * in (0- 9a-zing