Expand my Community achievements bar.

Validating the first position of a field?

Avatar

Level 2
I am new to LiveCycle Designer (7.0) and Javascript and I am hoping that someone can help or point me in the direction to find the answer to my question.



I am using a text file that needs to be verified to see if the first position contains only a 1, 2 or 0.



What I have is



var 1Var = /^d{1}$/



but I do not know what to do next.



Any help would be greatly appreciated.
2 Replies

Avatar

Former Community Member
This could be added on exit of that particular field (if the value is entered manually) -



var numFilter = /^[0-2]$/ //(regular expression for a value between 0 & 2)



if (!(numFilter.test(this.rawValue))) //(checks whether the thingy is met)

{

app.alert('bla bla bla ...\n'); //(alerts the user )

this.rawValue = "" //(resets the value to blank)

}

Avatar

Level 2
Hi Chris!



Thanks for the response.



I added what you gave me to the exit event but it seems to not work correctly.



This is what is in the script editor now. I am checking the format first and that seem to be working ok. But no matter what put in the text field I am getting the pop up.



///// Verify format



this.rawValue = util.printx("9999999 9",this.rawValue);



if (this.rawValue.length < 9)



{



app.alert("Please enter your Account ID.\n\nThe format is 9999999 9.");



xfa.host.setFocus("Account_ID_Number");



Account_ID_Number.rawValue = "";



}



else



{



this.rawValue = util.printx("9999999 9",this.rawValue);



}



var numFilter = /^[0-2]$/ //(regular expression for a value between 0 & 2)



if (!(numFilter.test(this.rawValue))) //(checks to see if value is met)

{

app.alert("Acount number must begin with 0, 1 or 2.") //(alerts the user )

this.rawValue = "" //(resets the value to blank)

}