- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
NSError* utilitiesCheckEmail(NSString* string)
{
NSInteger email_symbol_count=0;
NSInteger pos_email_symbol=0;
NSInteger pos_point=0;
NSInteger count=string.length;
if(count!=0)
{
unichar buffer[count];
[string getCharacters:buffer];
for(NSInteger i=0;i<count;i++)
{
unichar ch=buffer[i];
if( !( (ch>='a') && (ch<='z') ) && !( (ch>='A') && (ch<='Z') ) && !( (ch>='0') && (ch<='9') ) && (ch!='_') && (ch!='-') )
{
switch (ch)
{
case '@':
{
email_symbol_count++;
pos_email_symbol=i;
break;
}
case '.':
{
pos_point=i;
break;
}
default:
return [NSError errorWithDomain:NULL error:eErrorEmailInvalidFormat];
}
}
}
if( (email_symbol_count==1) && (pos_point!=0) && (pos_point>pos_email_symbol) && ((pos_point+1)<count) )
return NULL;
}
return [NSError errorWithDomain:NULL error:eErrorEmailInvalidFormat];
}
А в целом не такое уж и говно, лучше чем RFC-compliant regex.