• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Need help with regexp

Explorer ,
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

284

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 = "";

Votes

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...

Votes

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
Explorer ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

I want to extract first number from "Text2".

Votes

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 = "";

Votes

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
Explorer ,
Jun 09, 2022 Jun 09, 2022

Copy link to clipboard

Copied

LATEST

Thank you.

Votes

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