简体   繁体   中英

How to know half-width or full-width character?

I would like to know characters that contain in a String are half-width or full-width.

So I have tested like that:

 /* Checking typing password is valid or not.
 * If length of typing password is less than 6 or
 * is greater than 15 or password is composed by full-width character at least one,
 * it will return false.
 * If it is valid, it will return true.
 * @param cmdl
 * @param oldPassword
 * @return
 */
public boolean isValidNewPassword(String password) {

    if ((password.length() < 6)
            || (password.length() > 15) || (isContainFullWidth(password))) {
        return false;
    }

    return true;
}

/**
 * Checking full-width character is included in string.
 * If full-width character is included in string,
 * it will return true.
 * If is not, it will return false.
 * @param cmdl
 * @return
 */
public boolean isContainFullWidth(String cmdl) {
    boolean isFullWidth = false;
    for (char c : cmdl.toCharArray()) {
        if(!isHalfWidth(c)) {
            isFullWidth = true;
            break;
        }
    }

    return isFullWidth;
}

/**
 * Checking character is half-width or not.
 * Unicode value of half-width range:
 * '\u0000' - '\u00FF'
 * '\uFF61' - '\uFFDC'
 * '\uFFE8' - '\uFFEE'
 * If unicode value of character is within this range,
 * it will be half-width character.
 * @param c
 * @return
 */
public boolean isHalfWidth(char c)
{
    return '\u0000' <= c && c <= '\u00FF'
        || '\uFF61' <= c && c <= '\uFFDC'
        || '\uFFE8' <= c && c <= '\uFFEE' ;
}

But it is not OK for all full-width and half width characters.

So, may I know if you have any suggestion with this problem?

Half-width and full-width are used in asian language eg japanese

There are two type full-width and half-width when writing japanese characters.

half-width characters = アデチャエウィオプ

full-width characters = アsdファsヂオpp

Thanks a lot!

I would like to know characters that contain in a String are half-width or full-width.

So I have tested like that:

 /* Checking typing password is valid or not.
 * If length of typing password is less than 6 or
 * is greater than 15 or password is composed by full-width character at least one,
 * it will return false.
 * If it is valid, it will return true.
 * @param cmdl
 * @param oldPassword
 * @return
 */
public boolean isValidNewPassword(String password) {

    if ((password.length() < 6)
            || (password.length() > 15) || (isContainFullWidth(password))) {
        return false;
    }

    return true;
}

/**
 * Checking full-width character is included in string.
 * If full-width character is included in string,
 * it will return true.
 * If is not, it will return false.
 * @param cmdl
 * @return
 */
public boolean isContainFullWidth(String cmdl) {
    boolean isFullWidth = false;
    for (char c : cmdl.toCharArray()) {
        if(!isHalfWidth(c)) {
            isFullWidth = true;
            break;
        }
    }

    return isFullWidth;
}

/**
 * Checking character is half-width or not.
 * Unicode value of half-width range:
 * '\u0000' - '\u00FF'
 * '\uFF61' - '\uFFDC'
 * '\uFFE8' - '\uFFEE'
 * If unicode value of character is within this range,
 * it will be half-width character.
 * @param c
 * @return
 */
public boolean isHalfWidth(char c)
{
    return '\u0000' <= c && c <= '\u00FF'
        || '\uFF61' <= c && c <= '\uFFDC'
        || '\uFFE8' <= c && c <= '\uFFEE' ;
}

But it is not OK for all full-width and half width characters.

So, may I know if you have any suggestion with this problem?

Half-width and full-width are used in asian language eg japanese

There are two type full-width and half-width when writing japanese characters.

half-width characters = アデチャエウィオプ

full-width characters = アsdファsヂオpp

Thanks a lot!

I would like to know characters that contain in a String are half-width or full-width.

So I have tested like that:

 /* Checking typing password is valid or not.
 * If length of typing password is less than 6 or
 * is greater than 15 or password is composed by full-width character at least one,
 * it will return false.
 * If it is valid, it will return true.
 * @param cmdl
 * @param oldPassword
 * @return
 */
public boolean isValidNewPassword(String password) {

    if ((password.length() < 6)
            || (password.length() > 15) || (isContainFullWidth(password))) {
        return false;
    }

    return true;
}

/**
 * Checking full-width character is included in string.
 * If full-width character is included in string,
 * it will return true.
 * If is not, it will return false.
 * @param cmdl
 * @return
 */
public boolean isContainFullWidth(String cmdl) {
    boolean isFullWidth = false;
    for (char c : cmdl.toCharArray()) {
        if(!isHalfWidth(c)) {
            isFullWidth = true;
            break;
        }
    }

    return isFullWidth;
}

/**
 * Checking character is half-width or not.
 * Unicode value of half-width range:
 * '\u0000' - '\u00FF'
 * '\uFF61' - '\uFFDC'
 * '\uFFE8' - '\uFFEE'
 * If unicode value of character is within this range,
 * it will be half-width character.
 * @param c
 * @return
 */
public boolean isHalfWidth(char c)
{
    return '\u0000' <= c && c <= '\u00FF'
        || '\uFF61' <= c && c <= '\uFFDC'
        || '\uFFE8' <= c && c <= '\uFFEE' ;
}

But it is not OK for all full-width and half width characters.

So, may I know if you have any suggestion with this problem?

Half-width and full-width are used in asian language eg japanese

There are two type full-width and half-width when writing japanese characters.

half-width characters = アデチャエウィオプ

full-width characters = アsdファsヂオpp

Thanks a lot!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM