webdesign/JavaScript

How to apply css to only numbers in a text inside any element?

yunsoo.note 2021. 1. 15. 02:02

 

 

stackoverflow.com/questions/6097305/replace-nonnumeric-characters-with-javascript

 

replace nonNumeric characters with javascript?

I use this regular expression phone validation but when anybody enters any special characters *-/()-_ in the input.. (except +) I want to replace this characters with ""(none). How can I do ...

stackoverflow.com

\D matches anything that isn't a number; \d matches a number.

This below will remove all non-numeric characters in a given string:

myString = myString.replace(/\D/g,"");

 

stackoverflow.com/questions/19679719/how-to-apply-css-to-only-numbers-in-a-text-inside-or-any-pp-element

 

How to apply css to only numbers in a text inside/or any

 

element?

I am Using a Regional language unicode font-face in my site but the numbers are not looking good. So I want to apply new font-style or css to numbers only.. please help

stackoverflow.com

 

 

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<style>

.numbers

{

color:red;

font-size:30px;

}

</style>

</head>

<body>

 

<p>

View 11 new out of 1asdfasdf1241234 message(s) in your inbox. does it work?

</p>

 

<script type="text/javascript">

$('p').html(function(i,ab) {

return ab.replace(/\d+/g, function(v){

return "<span class='numbers'>" + v + "</span>";

});

});

</script>