I have a form in the input=text the user enters a number like 123456 i want to change this to 123-456
How can I put a dash after a certain numbers of characters?
I tried many functions but all of them wants to change or relapse a character and i don't want to change any thing i just want to insert a dash - after three characters in the string.
thank you.
this is the code that takes the number from the user i want to put this number in a function that insert the dash after three character in the sting inserted buy the user
<tr>
<td> <small>RIG CHARGE:</small> </td>
<td> <input type="text" name="rch" value="<?php echo $objWorksheet->getCellByColumnAndRow(6, 21)->getValue(); ?>"> </td>
</tr>
You can check the count of dashes in a string with: if str. Count(x => x == '-') !=
To insert hyphens into a JavaScript string, we can use the JavaScript string's replace method. We call phone. replace with a regex that has 3 capturing groups for capturing 2 groups of 3 digits and the remaining digits respectively. Then we put dashes in between each group with '$1-$2-$3' .
$string = "123456";
$insertion = "-";
$index = 3;
$result = substr_replace($string, $insertion, $index, 0);
echo $result;
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