mousemat24
asked on
Check is firstname has 2 chars at the most, and a max of 50
Hi
I have a string called
string name = "fred"; // this is valid
string name = "h"; // this is an error
how to I check the name variable to see if there is at least 2 chars
thanks
I have a string called
string name = "fred"; // this is valid
string name = "h"; // this is an error
how to I check the name variable to see if there is at least 2 chars
thanks
string name = "fred"; // this is valid
string name = "h"; // this is an error
if (name.Length() <= 2)
{
// this is an error
}
else
{
// this is valid
}
string name = "h"; // this is an error
if (name.Length() <= 2)
{
// this is an error
}
else
{
// this is valid
}
Oops!
string name = "fred"; // this is valid
string name = "h"; // this is an error
if (name.Length() < 2)
{
// this is an error
}
else
{
// this is valid
}
string name = "fred"; // this is valid
string name = "h"; // this is an error
if (name.Length() < 2)
{
// this is an error
}
else
{
// this is valid
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great, how about
must be greater then 2 and lower then 20?
must be greater then 2 and lower then 20?
string name = "fred"; // this is valid
string name = "h"; // this is an error
if (name.Length > 2 && name.Length < 20)
{
// this is valid
}
else
{
// this is an error
}
string name = "h"; // this is an error
if (name.Length > 2 && name.Length < 20)
{
// this is valid
}
else
{
// this is an error
}
Open in new window