Write a function. Test real cases. Improve your solution.
Validate a proposed team handle and return {valid, reason}. Apply checks in this exact order: a non-string returns {valid:false, reason:"type"}; a string outside 3–16 characters returns reason "length"; a string that does not begin with an ASCII letter or contains anything except ASCII letters, digits, and underscores returns reason "format". Otherwise return {valid:true, reason:"ok"}. Do not trim or change the candidate. Length means JavaScript string length. The candidate is a JSON value.
[ "Dev_team7" ]
{
"valid": true,
"reason": "ok"
}[ 123 ]
{
"valid": false,
"reason": "type"
}[ null ]
{
"valid": false,
"reason": "type"
}[ "1!" ]
{
"valid": false,
"reason": "length"
}[ "Ab_" ]
{
"valid": true,
"reason": "ok"
}[ "A123456789012345" ]
{
"valid": true,
"reason": "ok"
}[ "A1234567890123456" ]
{
"valid": false,
"reason": "length"
}[ "_dev" ]
{
"valid": false,
"reason": "format"
}[ " Dev " ]
{
"valid": false,
"reason": "format"
}[ "café" ]
{
"valid": false,
"reason": "format"
}[ "dev-team" ]
{
"valid": false,
"reason": "format"
}Your code runs in your browser. These exercises use synchronous JavaScript functions and built-in data types; DOM access, network requests, and npm imports are unavailable. Runs stop after about four seconds. Test results support self-study and don’t certify proficiency.