Concept explainers
//in c#
// I am having problem with my regex fitting the requirments
using System;
using System.Text.RegularExpressions;
namespace UsernameProcessor.Question
{
public sealed class UsernameProcessorService
{
/// <summary>
/// Requirements:
/// - A valid username shall be at least 4 characters.
/// - A valid username shall contain only letters, numbers and an optional underscore.
/// - A valid username shall start with a letter, and shall not end with an underscore.
/// </summary>
/// <param name="username"></param>
/// <returns>Whether or not the username is valid per the above requirements.</returns>
private static Regex sUserNameAllowedRegEx = new Regex(@"^(?=[a-zA-Z])[-\w.]{0,23}([a-zA-Z\d])$", RegexOptions.Compiled);
private static Regex sUserNameIllegalEndingRegEx = new Regex(@"(\-_)$", RegexOptions.Compiled);
public static bool IsValidUsername(string username)
{
if (string.IsNullOrEmpty(username)
|| !sUserNameAllowedRegEx.IsMatch(username)
|| sUserNameIllegalEndingRegEx.IsMatch(username))
{
return false;
}
throw new NotImplementedException("TODO: please validate our usernames!!!");
}
/// <summary>
/// Feel free to use the below main function to test and develop accordingly!
/// </summary>
public static void Main(string[] args)
{
Console.WriteLine(IsValidUsername("john_smith"));
Console.WriteLine(IsValidUsername("jsim_"));
}
}
}
Step by stepSolved in 3 steps with 2 images
- Hello, I was making a hangman simulation in C++. The code runs, but not fully. Could you identify the error and fix it? #include<iostream>#include<cstring> // for string class functions#include<fstream>#include <cctype>using namespace std; int main(){// define variable to get the response from user "Yes" or "No"string response;// Define index variableint w = 0;// define number of words that need to be guessed by the user assume 4const int WORDS = 4;// loopdo{// we will define the hangman bodyconst char body[] = "o/|\\|\\";// here we define the wordsstring words[WORDS] = {"MACAW", "SADDLE", "TOASTER", "XENOICIDE"};// fetch size or lengthstring xword(words[w].length(),'*');// define iterator to fetch the wordsstring::iterator i, ix = xword.begin();// define number of words to prompt for the userchar letters[26]={"\0"};// Now we define the variables which will be used in the simulationint n =0, xcount = xword.length();bool found = false, solved = false, hung =…arrow_forwardC# Solve this error using System; namespace RahmanA3P1BasePlusCEmployee { public class BasePlusCommissionEmployee { public string FirstName { get; } public string LastName { get; } public string SocialSecurityNumber { get; } private decimal grossSales; // gross weekly sales private decimal commissionRate; // commission percentage private decimal baseSalary; // base salary per week // six-parameter constructor public BasePlusCommissionEmployee(string firstName, string lastName, string socialSecurityNumber, decimal grossSales, decimal commissionRate, decimal baseSalary) { // implicit call to object constructor occurs here FirstName = firstName; LastName = lastName; SocialSecurityNumber = socialSecurityNumber; GrossSales = grossSales; // validates gross sales CommissionRate = commissionRate; // validates commission rate BaseSalary = baseSalary; // validates base…arrow_forwardPLEASE CODE IN PYTHON PLEASE USE NESTED CLASS FUNCTION Design a Point Class with attributes X and Y coordinates. The Class should have following functions: a) change the coordinates, b) return a 2 element list [x,y] c) print a Point object. d) return distance from this instance to a given [x,y] Also design a Line Class which has 2 Point attributes. The Line class should have functions for following behaviours: a) Return the length of the line. b) Print the equation of the line c) Find if this instance is equal in length to another line.arrow_forward
- PROGRAMMING LANGUAGE: C++ I need the code for clockType.h , clockTypelmp.cpp , main.cpp CLOCKTYPE.H code provided in this exercise [EVALUATE THE GIVEN CODE AND PROVIDE THE CORRECT CODE] class clockType { public: void setTime(int, int, int); void getTime(int&, int&, int&) const; void printTime() const; void incrementSeconds(); void incrementMinutes(); void incrementHours(); bool equalTime(const clockType&) const; private: int hr; int min; int sec; };arrow_forwardIn C# using System; using static System.Console; using System.Globalization; class JobDemo4 { static void Main() { RushJob[] jobs = new RushJob[5]; int x, y; double grandTotal = 0; bool goodNum; for(x = 0 ; x < jobs.Length; ++x) { jobs[x] = new RushJob(); Write("Enter job number "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } while(!goodNum) { Write("Sorry, the job number " + jobs[x].JobNumber + " is a duplicate. " + "\nPlease reenter "); jobs[x].JobNumber = Convert.ToInt32(ReadLine()); goodNum = true; for(y = 0; y < x; ++y) { if(jobs[x].Equals(jobs[y])) goodNum = false; } }…arrow_forwardcode this in RUBY programming languagearrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education