[Solved] Mobile number format [closed]


Check if the first character is a zero, if so replace it with 234. Note that the string replace method only will replace the first occurrence by default.

	$( '#button' ).click(function() {
	
		var nr	= $( '#nr' ).val();
		nr 	= nr.indexOf('0') == 0 ? nr.replace('0','234') : nr;
		
		$( '#result' ).html(nr);
	
	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input type="text" id="nr" />
<button type="button" id="button">Get</button>
<div id="result"></div>

2

solved Mobile number format [closed]