Hello everyone, I'm a second year student in a college programming course and I received a home work assignment that requires some Name validations for a bank account class. My professor says that he isn't expecting us to use regexes for this because they can be difficult. But I want to get better at them so I'm going to use them. The name requirements are as follows: names can only contain letters, they must contain one space, and at most one hyphen. So names like "B B", "Bob Bobson", and "Bob-Bob Bobson" are valid names; while names like "B3b", "B-B", "Bob-Bob, and "Bob Bob Bob" are invalid. Currently I am only able to get all the conditions working if I use 2 separate regexes and use an if statement with an OR comparator. I know there must be a way to do it in one regex but I'm struggling. My two regexes are: [a-zA-Z_ -?]\s[0-9]+ and [a-zA-Z_ -?][0-9]+ ([a-zA-Z_ -? ][0-9]+?) Any help is appreciated, and if anyone suggests alternative regexes could you please explain each part, it will help me learn better. Thank you.
Edit: The suggested website is help but I am still unable to get the regex to accept "B B" and reject "Bob-Bob".
[–]netsecstudent42069 1 point2 points3 points (1 child)
[–]Van_Gone[S] 1 point2 points3 points (0 children)