File tree Expand file tree Collapse file tree 1 file changed +14
-33
lines changed Expand file tree Collapse file tree 1 file changed +14
-33
lines changed Original file line number Diff line number Diff line change 10
10
def UsernameValidation (strParam ):
11
11
12
12
# username is between 4 and 25 characters
13
- if len (strParam ) <= 25 and len (strParam ) >= 4 :
14
- flag1 = True
15
- else :
16
- flag1 = False
13
+ if len (strParam ) < 4 or len (strParam ) > 25 :
14
+ return False
17
15
18
16
# start with a letter
19
- if str (strParam [0 ]).isalpha ():
20
- flag2 = True
21
- else :
22
- flag2 = False
23
-
24
- # contains only letters, numbers and underscore
25
- valid_grammar = "abcdefghijklmnopqrstuvwxyz0123456789_"
26
-
27
- for char in strParam :
28
- if str (char ).isalpha () == False :
29
- if char in valid_grammar :
30
- flag3 = True
31
- else :
32
- flag3 = False
33
-
34
- else :
35
- if str .lower (char ) in valid_grammar :
36
- flag3 = True
37
- else :
38
- flag3 = False
39
-
17
+ if not str (strParam [0 ]).isalpha ():
18
+ return False ;
40
19
41
20
# can't end with an underscore
42
- if str (strParam [- 1 ]) != '_' :
43
- flag4 = True
44
- else :
45
- flag4 = False
21
+ if str (strParam [- 1 ] ) == '_' :
22
+ return False ;
23
+
24
+ # contains only letters, numbers and underscore
25
+ valid_grammar = set ('abcdefghijklmnopqrstuvwxyz0123456789_' )
46
26
47
- final_output = flag1 and flag2 and flag3 and flag4
27
+ for ch in strParam :
28
+ if ch .lower () not in valid_grammar :
29
+ return False ;
48
30
49
- # code goes here
50
- return final_output
31
+ return True
51
32
52
33
# keep this function call here
53
34
TC1 = "aa_"
54
- TC2 = "u__hello_world123 "
35
+ TC2 = "uaa__hello_worldW "
55
36
56
37
print (TC1 , UsernameValidation (TC1 ))
57
38
print (TC2 , UsernameValidation (TC2 ))
You can’t perform that action at this time.
0 commit comments