Can someone please help me with a script that will reformat numeric character within a string from like "this is my mobile number 3456353433" to " This is my mobile number 3456 353 433". i will appreciate if it can likewise come with a functionality that tests if the string contains numeric character of 10 digits then pops up with a jquery dialog box asking if the user desires the mobile number to be reformatted. Thank you
-
What have you tried so far? Also, are you trying to do this in JavaScript, asp.net, or vb.net?AMACB– AMACB2016年02月15日 00:45:41 +00:00Commented Feb 15, 2016 at 0:45
-
i was trying to do it in vb.net and javascript, but the challenge with my script is at the point where javascript dialog box pops up asking if the client desires to reformat the numeric character in the string, the javascript is not waiting for the client to respond . it just goes ahead and run the following scriptPope– Pope2016年02月17日 02:16:12 +00:00Commented Feb 17, 2016 at 2:16
1 Answer 1
One way using jquery
<a class="fix">This is my mobile number 3456353433</a>
Code
$(function() {
var data = $('.fix').text();
var arr = data.split(' ');
//check if numeric and 10 numbers
if (isNaN(arr[5]) == false && arr[5].length == 10) {
//show popup, if yes run the format function
format();
}
function format() {
var first = arr[5].substring(0,4);
var second = arr[5].substring(4,20);
second = second.replace(/(.{3})/g,"1ドル ")
$('.fix').text("This is my mobile number "+ first+" "+second);
}
});
answered Feb 15, 2016 at 0:48
Tasos
5,3491 gold badge17 silver badges26 bronze badges
Sign up to request clarification or add additional context in comments.
9 Comments
Blackwood
Are you assuming that the number is always the 6th work in the string? I'm not sure that is what the OP intended.
Tasos
@Blackwood -- i just went by "reformat numeric character within a string from like "This is my mobile number 3456353433" to " This is my mobile number 3456 353 433" and all the other bits in the Q. if (within a string from like) is an example then i provided an example on how to that.
Blackwood
Fair enough. I'm just suggesting that any other examples seem unlikely to have 5 words followed by a number. The OP really needs to explain what the rules are.
Tasos
@Blackwood -- the Q is all in one block of text and its a bit hard to grasp. :)
Pope
Thank you, yes, please i will appreciate if the position of the number is treated as a variable. That is it might be in the 6th position or not.
|
default