JavaScript – Remove Specific Characters from a String

javascriptstring

I am creating a form to lookup the details of a support request in our call logging system.

Call references are assigned a number like F0123456 which is what the user would enter, but the record in the database would be 123456. I have the following code for collecting the data from the form before submitting it with jQuery ajax.

How would I strip out the leading F0 from the string if it exists?

$('#submit').click(function () {        
            
var rnum = $('input[name=rnum]');
var uname = $('input[name=uname]');

var url = 'rnum=' + rnum.val() + '&uname=' + uname.val();

Best Answer

Simply replace it with nothing:

var string = 'F0123456'; // just an example
string.replace(/^F0+/i, ''); '123456'
Related Question