Need help with regexp

Community Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Why this doesn't work?

var f = this.getField("Text2").value;
var reg = /\+?\d+/;
var str = f.match(reg);
event.value = str;

 

I tested it in that site w3.schools.com and there it works, but in pdf it doesn't work.

TOPICS
JavaScript

Views

34

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 09, 2022 Jun 09, 2022

Use this code:

 

var f = this.getField("Text2").value;
var reg = /\d+/;
var str = f.match(reg);
if (str!=null) event.value = str[0];
else event.value = "";

Likes

Translate

Translate
Community Expert ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

You need to explain what you're trying to achieve...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

I want to extract first number from "Text2".

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

Use this code:

 

var f = this.getField("Text2").value;
var reg = /\d+/;
var str = f.match(reg);
if (str!=null) event.value = str[0];
else event.value = "";

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

LATEST

Thank you.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines