Extract numbers from a string?

Aeden Frost
Tera Contributor

Hi everyone, hope you're having a nice day.

 

I have a field for a string with a number (Eg. Box of 100)

I want to be able to extract the number from the string (100) and move that field to another field to be used in another string field.

 

I've made a client script like this but it does not seem to be working in the way that is intended, any help would be much appreciated 🙂

function onSubmit() {
	
var txt = ('u_internal_unit');
var numb = txt.match(/\d/g);
numb = numb.join("");
var ans = ('iui_amount');	
ans = (numb); 
	
}
1 ACCEPTED SOLUTION

g_form.getValue('<field name>') will get the value of the field.

g_form.setValue('<field name>', <value>) will set the value to the field.

View solution in original post

7 REPLIES 7

Anil Lande
Kilo Patron

Hi,

What is not working here?

Are you printing result in alert?

function onSubmit() {
	
var txt = ('u_internal_unit');
var numb = txt.match(/\d/g);
numb = numb.join("");

alert(numb);  // numb contains number here
var ans = ('iui_amount');	
ans = (numb);  // 
	
}

 

Thanks,

Anil Lande

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Kartik Sethi
Tera Guru
Tera Guru

Hi @Aeden Frost 

 

Please try the code provided below:

function onSubmit() {
    var txt = ('u_internal_unit'),
        numb = text.match(/(\d+)/g),

        numb = numb.join(',');

    //Not sure what is the purpose of below line??
    var ans = ('iui_amount');
    ans = (numb);

}

 


Please mark my answer as correct if this solves your issues!

If it helped you in any way then please mark helpful!

 

Thanks and regards,

Kartik

Unfortunately it is giving me an error;

 

onSubmit script error: ReferenceError: text is not defined:
function () { [native code] }

Hi @Aeden Frost 

My apologies!

I did a typo! Instead of txt I wrote text.

function onSubmit() {
    var txt = ('u_internal_unit'),
        numb = txt.match(/(\d+)/g),

        numb = numb.join(',');

    //Not sure what is the purpose of below line??
    var ans = ('iui_amount');
    ans = (numb);

}