How do I make a function to insert a character into the middel of a text?
I want something like this:
The user types “999999AAAA” and leaves the field.
A messagebox asks “did you mean 999999-AAAA?”, the users choose “yes” and a hyphen is inserted in the text.
I have made a regex to look for the “999999AAAA” and a messagebox but how can I change the field value to have a dash in the middle?
var myRegex = /\d{6}[a-zA-Z]{4}/;
if (this.rawValue != null || this.rawValue != ''){
if (this.rawValue.match(myRegex)){
var nChoice = xfa.host.messageBox("Did you mean 999999-AAAA?", "Messagebox title",2,2);
if (nChoice === 4)
{
Some function to add the hyphen
}
if (nChoice === 3)
{
xfa.host.setFocus(nextField);
}
}
}
Regards,
Kirstine
Solved! Go to Solution.
Views
Replies
Total Likes
I found a useful script here which made it posible for me to make the function I wanted.
var myRegex = /\d{6}[a-zA-Z]{4}/;
if (this.rawValue != null || this.rawValue != '')if (this.rawValue.match(myRegex)){
var nChoice = xfa.host.messageBox("Did you mean 999999-AAAA?", "Messagebox title",2,2);
if (nChoice === 4)
{
function isEmpty(str) {
if(str == null || str.length == 0) {
return true;
}
return false;
}
try
{
var vEID = this.rawValue;if (!isEmpty(vEID)){
this.rawValue = vEID.substr(0,6)+"-"+vEID.substr(6).toUpperCase();
}
}
catch(e){
app.alert(e)
}
xfa.host.setFocus(nextField);
}
if (nChoice === 3)
{
xfa.host.setFocus(nextField);
}
}}
Views
Replies
Total Likes
Hi Kirstine,
Could use just specify a display pattern in Designer?
Have a look at this example for changing the display patern at runtime: http://assure.ly/fRtTyB. You could incorporate this in your if/else statement.
Hope that helps,
Niall
Views
Replies
Total Likes
I could, if I was shure the input always would match that pattern but I can’t be. Most inputs will match the pattern 999999-AAAA but the field should be open for all other input patterns as well.
Views
Replies
Total Likes
Okay,
Try this Display Pattern:
text{999999-AAAA}|text{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}
This should work automatically without script.
Niall
I found a useful script here which made it posible for me to make the function I wanted.
var myRegex = /\d{6}[a-zA-Z]{4}/;
if (this.rawValue != null || this.rawValue != '')if (this.rawValue.match(myRegex)){
var nChoice = xfa.host.messageBox("Did you mean 999999-AAAA?", "Messagebox title",2,2);
if (nChoice === 4)
{
function isEmpty(str) {
if(str == null || str.length == 0) {
return true;
}
return false;
}
try
{
var vEID = this.rawValue;if (!isEmpty(vEID)){
this.rawValue = vEID.substr(0,6)+"-"+vEID.substr(6).toUpperCase();
}
}
catch(e){
app.alert(e)
}
xfa.host.setFocus(nextField);
}
if (nChoice === 3)
{
xfa.host.setFocus(nextField);
}
}}
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies