-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusername_validation.c
77 lines (52 loc) · 1.36 KB
/
username_validation.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
username_validation.c
coderbyte exercise:
CodelandUsernameValidation(str) take the str parameter being passed
and determine if the string is a valid username according to the
following rules:
1. The username is between 4 and 25 characters.
2. It must start with a letter.
3. It can only contain letters, numbers, and the underscore character.
4. It cannot end with an underscore character.
If the username is valid then your program should return the string
true, otherwise return the string false.
Examples
Input: "aa_"
Output: false
Input: "u__hello_world123"
Output: true
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
char* CodelandUsernameValidation(char str[]) {
int i;
int size = strlen(str);
if(size<4 || size>25)
return "false";
if( !isalpha(str[0]) )
return "false";
for(i=0;i<size;i++){
if(i==size-1){
if(str[i]=='_')
return "false";
}
if( isalnum(str[i]) || str[i]=='_'){
;
}
else{
return "false";
}
}
return "true";
}
int main(void) {
char str[] = "u__hello_world123";
//char str[] = "1234567890123456789012345";
printf("%s\n",CodelandUsernameValidation(str));
// keep this function call here
//CodelandUsernameValidation(coderbyteInternalStdinFunction(stdin));
return 0;
}
/* end of username_validation.c */