How to remove every character after number of digits [duplicate]












-1
















This question already has an answer here:




  • How can I cut a string after X characters?

    4 answers




How to remove every character after 9 digits.



I tried the following but is removing the whole word



$(this).val(str.replace(/^.{9,}$/g,""));









share|improve this question















marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 12:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

    – Wiktor Stribiżew
    Nov 14 '18 at 11:48


















-1
















This question already has an answer here:




  • How can I cut a string after X characters?

    4 answers




How to remove every character after 9 digits.



I tried the following but is removing the whole word



$(this).val(str.replace(/^.{9,}$/g,""));









share|improve this question















marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 12:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 1





    Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

    – Wiktor Stribiżew
    Nov 14 '18 at 11:48
















-1












-1








-1









This question already has an answer here:




  • How can I cut a string after X characters?

    4 answers




How to remove every character after 9 digits.



I tried the following but is removing the whole word



$(this).val(str.replace(/^.{9,}$/g,""));









share|improve this question

















This question already has an answer here:




  • How can I cut a string after X characters?

    4 answers




How to remove every character after 9 digits.



I tried the following but is removing the whole word



$(this).val(str.replace(/^.{9,}$/g,""));




This question already has an answer here:




  • How can I cut a string after X characters?

    4 answers








javascript regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 11:48









Flimzy

38.4k96597




38.4k96597










asked Nov 14 '18 at 11:47









Khaled RamadanKhaled Ramadan

3318




3318




marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 12:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 14 '18 at 12:09


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

    – Wiktor Stribiżew
    Nov 14 '18 at 11:48
















  • 1





    Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

    – Wiktor Stribiżew
    Nov 14 '18 at 11:48










1




1





Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

– Wiktor Stribiżew
Nov 14 '18 at 11:48







Your regex does not match only digits, it matches a line of 9 or more non-linebreak chars. What do you mean to do? Please clarify with an example.

– Wiktor Stribiżew
Nov 14 '18 at 11:48














1 Answer
1






active

oldest

votes


















-1














You don't need regex to do this. You can use .substr()



Here I used str.substr(0, 9); where 0 is the start of the string you want to keep, and 9 is the length of the portion you want to keep (ie: to the 0+9th index is where it will cut off the string):




let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);








share|improve this answer


























  • Thank you for you answer substring solve my issue

    – Khaled Ramadan
    Nov 14 '18 at 11:57


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









-1














You don't need regex to do this. You can use .substr()



Here I used str.substr(0, 9); where 0 is the start of the string you want to keep, and 9 is the length of the portion you want to keep (ie: to the 0+9th index is where it will cut off the string):




let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);








share|improve this answer


























  • Thank you for you answer substring solve my issue

    – Khaled Ramadan
    Nov 14 '18 at 11:57
















-1














You don't need regex to do this. You can use .substr()



Here I used str.substr(0, 9); where 0 is the start of the string you want to keep, and 9 is the length of the portion you want to keep (ie: to the 0+9th index is where it will cut off the string):




let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);








share|improve this answer


























  • Thank you for you answer substring solve my issue

    – Khaled Ramadan
    Nov 14 '18 at 11:57














-1












-1








-1







You don't need regex to do this. You can use .substr()



Here I used str.substr(0, 9); where 0 is the start of the string you want to keep, and 9 is the length of the portion you want to keep (ie: to the 0+9th index is where it will cut off the string):




let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);








share|improve this answer















You don't need regex to do this. You can use .substr()



Here I used str.substr(0, 9); where 0 is the start of the string you want to keep, and 9 is the length of the portion you want to keep (ie: to the 0+9th index is where it will cut off the string):




let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);








let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);





let str = "123456789Hello world!";
let res = str.substr(0, 9);
console.log(res);






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 12:15

























answered Nov 14 '18 at 11:51









Nick ParsonsNick Parsons

7,0752724




7,0752724













  • Thank you for you answer substring solve my issue

    – Khaled Ramadan
    Nov 14 '18 at 11:57



















  • Thank you for you answer substring solve my issue

    – Khaled Ramadan
    Nov 14 '18 at 11:57

















Thank you for you answer substring solve my issue

– Khaled Ramadan
Nov 14 '18 at 11:57





Thank you for you answer substring solve my issue

– Khaled Ramadan
Nov 14 '18 at 11:57



Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python