So I'm trying to convert PX to EM, but if a user enters 16px, instead of 16 I want to strip the PX. Here's what I'm using
.replace(/^EM+/i, '')
But for some reason it's not removing.
Here's a demo. Enter any value with PX, and you'll get NaN. Also is there a way to suppress the NaN so that then it won't show?
My understanding of this is that the ^ character specifies the start of the line, and the + character is specifying that there must be at least one of them... This example works:
.replace(/EM+/i, '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With