Expand my Community achievements bar.

Text Field Pattern Assistance

Avatar

Former Community Member
New to Adobe LiveCycle Designer 7.0, so bear with me.



I have created a form to host on a website. I would like to standardize some of the entries. For example, I have a text field to enter a URL. I would like the data to be collected as http://xxx.xxx.xxx. If a user does not enter it correctly, a window pops up with telling them to use the proper format, and showing an example. I have experimented and searched the web for a way to make this work, but I am stuck.



The others fields needed are phone, (xxx) xxx-xxxx, and email xxx@xxx.xxx. I see that there are pre-defined patterns for those, and I can get the pop up window to ask for the proper syntax (Validation Pattern), but when I enter data in the field, (888) 555-1212, it still yields a validation error.



Data collected in the form will eventually be collected by a database, which is why I would like uniform entries.



Any help is truly appreciated,

Chris
3 Replies

Avatar

Former Community Member
I think that the best solution in this case is using the regular expressions, for example:



b On TextField Validate Event






var r = new RegExp();

// Create a new Regular Expression Object.




r.compile("^http[s]?:+//(\\w[\\w-]*\\w\\.)+[a-z0-9\\S]*$","i");





r.test(this.rawValue);




I'm not the ideal person to explain the correct way to use the regular expressions, because I hate to use them :P, nevertheless i hope it can helps you.




Good luck,

Dan

Avatar

Former Community Member
I am not much of a JavaScript writer, but I understood that. It actaully worked really well for my current needs.



I am trying to decipher "^http[s]?:+//(\\w[\\w-]*\\w\\.)+[a-z0-9\\S]*$","i"

because as I mentioned, I need one for phone, (xxx) xxx-xxxx, and email xxx@xxx.xxx as well.



Any help there?

Avatar

Former Community Member
function validateEmail(theEmail){

var str = new String(theEmail);

index1 = str.indexOf("@");

index2 = str.indexOf(".");

if ((index1==-1)||(index2==-1)||(index1>index2)) {

scoMsg.alertMessage('email format:\n\n xxx@xxxx.xx');

return false;

}

else return true;

}



function validateTelef(theTlf){

// Valid format: 977.456.987 ó 974 567 123 ó 123456789 ó 123456 789

var expr = new RegExp("[0-9]{3}[. ]?[0-9]{3}[. ]?[0-9]{3}");

if (!expr.test(theTlf)){

expr = new RegExp("[(][+]?[0-9]{2}[)][ ][0-9]{3}[. ]?[0-9]{3}[. ]?[0-9]{3}");

if (!expr.test(theTlf)){

scoMsg.alertMessage('Valid format:\n\n 123456789 \n 973 456 789 \n 973.123.456 \n (34) 977.123.456 \n (+34) 856.234.899');

return false;

}

}

return true;

}



Or something like this! :)