email 주소 형식체크, 유효성 검증하기 - PowerBuilder(파워빌더)

 
반응형


내년부터 법인에서는 전자세금계산서를 의무적으로 발행 및 사용해야 한다고 해서, 우선은 업체들의 이메일을 입력받는 항목을 추가했는데...
PB에서 이메일이 제대로 입력이 되었는지 검증하는 루틴도 만들어야 할듯...

itemchanged event에서 체크를 해주면 될듯한데,
함수를 만들어서 할까... 어쩔까하다가 match 함수가 생각남...
근데 난정말 정규식이 싫다...-_-;;

검색을 해보니 나오기는 하는데, 뭔소리 인지도 모르겠고, 몇가지 안되는 검증도 있다는...

Email Address Validation - Failing on space in string
Asked by pemurray in sybase PowerBuilder Programming Language
Tags: Powerbuilder, 11.0
Greetings All,

http://www.experts-exchange.com/Programming/Editors_IDEs/PowerBuilder/Q_23318560.html

I have code from buasuwan that allows me to check an email address to make sure it is properly formatted.  But it still seems to allow an email address to pass if it has a space in it.  I am not sure what is wrong.  Can someone help please?

Here is the code and pattern:

If email1 <> "" then
if match(email1,'^[a-zA-Z0-9][a-zA-Z\0-9\-_\.]*[^.]\@[^.][a-zA-Z\0-9\-_\.]+\.[a-zA-Z\0-9\-_\.]*[a-zA-Z\0-9]+$') then
email1flag = 'Y'     
end if
end if

우선은 급한데로 쓰기는 했는데, 좀 찜찜하다...
앞으로는 자주 사용을 하게 될듯한데, 뭔소리인지도 모르는 match함수는 버려버리고,
제대로된 function이나 하나 만들어 놔야 겠다...


Description

Determines whether a string's value contains a particular pattern of characters.

Syntax

Match ( string, textpattern )
Argument    Description
string    The string in which you want to look for a pattern of characters
textpattern    A string whose value is the text pattern
Return value
Boolean. Returns TRUE if string matches textpattern and FALSE if it does not. Match also returns FALSE if either argument has not been assigned a value or the pattern is invalid. If any argument's value is NULL, Match returns NULL.
Usage
Match enables you to evaluate whether a string contains a general pattern of characters. To find out whether a string contains a specific substring, use the Pos function.
Textpattern is similar to a regular expression. It consists of metacharacters, which have special meaning, and ordinary characters, which match themselves. You can specify that the string begin or end with one or more characters from a set, or that it contain any characters except those in a set.

A text pattern consists of metacharacters, which have special meaning in the match string, and nonmetacharacters, which match the characters themselves.
The following tables explain the meaning and use of these metacharacters:
Metacharacter    Meaning    Example
Caret (^)    Matches the beginning of a string    ^C matches C at the beginning of a string
Dollar sign ($)    Matches the end of a string    s$ matches s at the end of a string
Period (.)    Matches any character    . . . matches three consecutive characters
Backslash (\)    Removes the following metacharacter's special characteristics so that it matches itself    \$ matches $
Character class (a group of characters enclosed in square brackets ([ ]))    Matches any of the enclosed characters    [AEIOU] matches A, E, I, O, or UYou can use hyphens to abbreviate ranges of characters in a character class. For example, [A-Za-z] matches any letter
Complemented character class (first character inside the brackets is a caret)    Matches any character not in the group following the caret    [^0-9] matches any character except a digit, and [^A-Za-z] matches any character except a letter
The metacharacters asterisk (*), plus (+), and question mark (?) are unary operators that are used to specify repetitions in a regular expression:
Metacharacter    Meaning    Example
* (asterisk)    Indicates zero or more occurrences    A* matches zero or more As (no As, A, AA, AAA, and so on)
+ (plus)    Indicates one or more occurrences    A+ matches one A or more than one A (A, AAA, and so on)
? (question mark)    Indicates zero or one occurrence    A? matches an empty string ("") or A
Sample patterns 
The following table shows various text patterns and sample text that matches each pattern:
This pattern    Matches
AB    Any string that contains AB; for example, ABA, DEABC, graphAB_one
B*    Any string that contains 0 or more Bs; for example, AC, B, BB, BBB, ABBBC, and so on
AB*C    Any string containing the pattern AC or ABC or ABBC, and so on (0 or more Bs)
AB+C    Any string containing the pattern ABC or ABBC or ABBBC, and so on (1 or more Bs)
ABB*C    Any string containing the pattern ABC or ABBC or ABBBC, and so on (1 B plus 0 or more Bs)
^AB    Any string starting with AB
AB?C    Any string containing the pattern AC or ABC (0 or 1 B)
^[ABC]    Any string starting with A, B, or C
[^ABC]    A string containing any characters other than A, B, or C
^[^abc]    A string that begins with any character except a, b, or c
^[^a-z]$    Any single-character string that is not a lowercase letter (^ and $ indicate the beginning and end of the string)
[A-Z]+    Any string with one or more uppercase letters
^[0-9]+$    Any string consisting only of digits
^[0-9][0-9][0-9]$    Any string consisting of exactly three digits
^([0-9][0-9][0-9])$    Any consisting of exactly three digits enclosed in parentheses


This statement returns TRUE if the text in sle_ID begins with one or more uppercase or lowercase letters (^ at the beginning of the pattern means that the beginning of the string must match the characters that follow):

Match(sle_ID.Text, "^[A-Za-z]")

This statement returns FALSE if the text in sle_ID contains any digits (^ inside a bracket is a complement operator):

Match(sle_ID.Text, "[^0-9]")

This statement returns TRUE if the text in sle_ID contains one uppercase letter:

Match(sle_ID.Text, "[A-Z]")

This statement returns TRUE if the text in sle_ID contains one or more uppercase letters (+ indicates one or more occurrences of the pattern):

Match(sle_ID.Text, "[A-Z]+")

This statement returns FALSE if the text in sle_ID contains anything other than two digits followed by a letter (^ and $ indicate the beginning and end of the string):

Match(sle_ID.Text, "^[0-9][0-9][A-Za-z]$")


 
반응형