How to count the number of full-width characters

user_ms
Tera Expert

I would like to know how to count the number of full-width characters among the full-width half-width characters entered in a column in onChange of the client script.

Could you please tell me?

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage

Hi @user_ms 

 

// Count the number of full-width characters in newValue
    var fullWidthCount = countFullWidthCharacters(newValue);

    // Example: Update a field or log the count (replace ‘field_name’ with your actual field’s name)
    alert("Number of full-width characters: " + fullWidthCount); // Or use g_form.setValue('field_name', fullWidthCount) to set it in a field
}

/**
 * Function to count full-width characters in a string.
 * This uses a simple range check. For more accurate results, adjust the ranges or use specific character checks as needed for your application.
 */
function countFullWidthCharacters(str) {
    var count = 0;
    for (var i = 0; i < str.length; i++) {
        // Check if the character is full-width by its Unicode value
        // Basic range checks (U+3000 to U+FFEF include common full-width characters - adjust as needed)
        if (str.charCodeAt(i) >= 0x3000 && str.charCodeAt(i) <= 0xFFEF) {
            count++;
        }
    }
    return count;
}

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..

- Keep Learning ‌‌

Thanks & Regards 

Deepak Sharma

View solution in original post

1 REPLY 1

Deepak Shaerma
Kilo Sage

Hi @user_ms 

 

// Count the number of full-width characters in newValue
    var fullWidthCount = countFullWidthCharacters(newValue);

    // Example: Update a field or log the count (replace ‘field_name’ with your actual field’s name)
    alert("Number of full-width characters: " + fullWidthCount); // Or use g_form.setValue('field_name', fullWidthCount) to set it in a field
}

/**
 * Function to count full-width characters in a string.
 * This uses a simple range check. For more accurate results, adjust the ranges or use specific character checks as needed for your application.
 */
function countFullWidthCharacters(str) {
    var count = 0;
    for (var i = 0; i < str.length; i++) {
        // Check if the character is full-width by its Unicode value
        // Basic range checks (U+3000 to U+FFEF include common full-width characters - adjust as needed)
        if (str.charCodeAt(i) >= 0x3000 && str.charCodeAt(i) <= 0xFFEF) {
            count++;
        }
    }
    return count;
}

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..

- Keep Learning ‌‌

Thanks & Regards 

Deepak Sharma