-1

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

asked Feb 14, 2016 at 23:58
2
  • What have you tried so far? Also, are you trying to do this in JavaScript, asp.net, or vb.net? Commented 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 script Commented Feb 17, 2016 at 2:16

1 Answer 1

2

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);
}
});

Demo

answered Feb 15, 2016 at 0:48
Sign up to request clarification or add additional context in comments.

9 Comments

Are you assuming that the number is always the 6th work in the string? I'm not sure that is what the OP intended.
@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.
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.
@Blackwood -- the Q is all in one block of text and its a bit hard to grasp. :)
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.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.