Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please advise on PB support of Regular Expressions

Status
Not open for further replies.

Geser

Programmer
Jul 19, 2005
4
US
I an trying to create a code which would be used to validate data entered to be a plausible social security number - and so far I have been unable to come up with the code for it in PowerBuilder. Any assistance is appreciated. Thanks!
 
How do you define a plausible number? based on the number of digits? some sort of check sum?

Matt

"Nature forges everything on the anvil of time
 
Thanks for your reply!. Plausible SS number is defined as ###-##-#### (3 digits, followed by dash, followed by 2 digits, followed by dash, followed by 4 digits). Thanks!
 
Well if you are storing this number, you probably won't want to store the dashes. In the itemchanged event of your datawindow (assuming you are using a datawindow) make sure the data entered has a length of 9.
Code:
IF (Len(data) <> 9) THEN
   //error condition
END IF
If you are using an Editmask control in the Losefocus event
Code:
IF (Len(this.text) <> 9) AND (Len(this.text) > 0) THEN
   //error condition
END IF
You can set up an edit mask on the display of the field to show the dashes to the user (i.e., ###-##-####).

Matt

"Nature forges everything on the anvil of time
 
hey geser!

pb doesn't support regex,there's just a simple dialect which can be used with the match() function.
however this should really be ok for the purpose, it returns true for any string matching exactly your SS#:

Code:
Match(/*string str_var*/, &
"^([0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9])$")

for regexes in pb check perllib which can be used to easily integrate perl in pb-code. but you won't need that here truely

__________________________________________
a programmer is a tool that converts coffee into code...
aschi666, sthcomputing.de
 
... but matt's approach is totaly correct too. you can use match() in code and the edit mask control to check what the user entered.

tell us if we helped you!

__________________________________________
a programmer is a tool that converts coffee into code...
aschi666, sthcomputing.de
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top