- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 09:17 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 09:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2024 09:28 AM
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