Question #2567   Proposée par Answiki le 25/11/2021 à 17:52:22 UTC

Comment tester si une chaîne est exclusivement composée de lettres ou de chiffres en JavaScript ?

Answer   Submitted by Answiki on 11/25/2021 at 05:53:06 PM UTC

La fonction suivante retourne vrai si la chaîne de caractères passée en paramètre est exclusivement composée de caractères alphanumériques (a-z ; A-Z ; 0-9) :

function isAlphanumeric(string)
{
    for ( var i = 0; i < string.length; i++ )
    {
        ch = string.charAt(i);
        if (!(ch >= '0' && ch <= '9') && 	// Numeric (0-9)
        !(ch >= 'A' && ch <= 'Z') && 		// Upper alpha (A-Z)
        !(ch >= 'a' && ch <= 'z')) 			// Lower alpha (a-z)
        return false;
    }
    return true;
}

3 events in history
Answer by Answiki on 11/25/2021 at 05:53:06 PM

La fonction suivante retourne vrai si la chaîne de caractères passée en paramètre est exclusivement composée de caractères alphanumériques (a-z ; A-Z ; 0-9) :

function isAlphanumeric(string)
{
    for ( var i = 0; i < string.length; i++ )
    {
        ch = string.charAt(i);
        if (!(ch >= '0' && ch <= '9') && 	// Numeric (0-9)
        !(ch >= 'A' && ch <= 'Z') && 		// Upper alpha (A-Z)
        !(ch >= 'a' && ch <= 'z')) 			// Lower alpha (a-z)
        return false;
    }
    return true;
}

Question by Answiki 11/25/2021 at 05:52:22 PM
Comment tester si une chaîne est exclusivement composée de caractères alphanumériques en JavaScript ?
Question by Answiki 11/25/2021 at 05:52:22 PM
Comment tester si une chaîne est exclusivement composée de lettres ou de chiffres en JavaScript ?
# ID Query URL Count

Icons proudly provided by Friconix.