Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Validate field that there is a comma

Avatar

Level 3

I want to have the user enter their name as Last Name, First Name, with the comma. I need to be able to validate that there is a comma, figuring if there is not, they did not enter the name correctly and will give them a message saying such.

I have found a few things, but they don't seem to be working. Plus not sure where it would go, exit, change, validate, etc.?

I'm thinking something along the line of an e-mail validation, where it would check if there is text before and after the comma.

Thanks, Gary

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

use a regular expression in a script or the exit event to look for a comma.

This sample will check if there are at least two characters for the last name which are followed by a comma followed by at least two characters for the first name.

if (!$.rawValue.match(/\D{2}?\s*,+\s\D{2}?/g)) {

          xfa.host.messageBox("No first name or last name or comma entered!");

}

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi,

use a regular expression in a script or the exit event to look for a comma.

This sample will check if there are at least two characters for the last name which are followed by a comma followed by at least two characters for the first name.

if (!$.rawValue.match(/\D{2}?\s*,+\s\D{2}?/g)) {

          xfa.host.messageBox("No first name or last name or comma entered!");

}

Avatar

Level 3

That's what I was looking for, thanks!

Avatar

Level 5

Radzmar,

I have messed with your code above to try and make the script validate a field with:

Last, First MI

as of yet I haven't been able to figure out what is missing. I have tried changing the script to:

(/\D{2}?\s*,+\s\D{2}?/g+\s\D{1}?/g)

to account for the Middle Intial. A name having hyphens or any other digits isn't a problem. I would just like to check for the format [a-zA-Z0-9adgk][,]\s[a-zA-Z0-9adgk]\s[a-zA-Z0-9adgk] meaning

[anything], [anything] [anything]. None of these work however.

Any direction you could point me to get closer to the correct script would be appreciated. Thank you.

I am also getting an error in the console regardless of what is entered.

$.rawValue is null

7:XFA:form1[0]:#subform[0]:TextField1[0]:exit

TypeError: $.rawValue is null

7:XFA:form1[0]:#subform[0]:TextField1[0]:exit

https://workspaces.acrobat.com/?d=391oP-DspRpbACpKdvL1Yw