Skip to main content
Inspiring
May 22, 2024
Answered

How to avoid a double percentage ?

  • May 22, 2024
  • 1 reply
  • 339 views

Hi, I have this code to bring a percentage automatically after the number :

if (event.value) event.value += "%";

 

What's the code to make it happen, but only if someone didn't write a percentage themselves in the first place ?

This topic has been closed for replies.
Correct answer try67

if (event.value && /%$/.test(event.value)==false) event.value += "%";

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 22, 2024

if (event.value && /%$/.test(event.value)==false) event.value += "%";