- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
LMAO...That's Brillant!
Admin
LMAO...That's Brillant!
Admin
And if you use some cleaner coding style the next time you want to show your own stuff then your contribution could have been usefull as well:
<FONT color=#000000><FONT size=2><FONT face="Courier New" size=1>private static readonly Regex local_part_pattern = new Regex(@"^([a-zA-Z0-9_\-\.+]+)$");
private static readonly Regex domain_part_pattern = new Regex(@"^((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$");
public bool is_valid_email(string email)
{
int at_position = email.IndexOf("@");
if (at_position == -1) return false;
return local_part_pattern.IsMatch(email.Substring(0, at_position)) &&
domain_part_pattern.IsMatch(email.Substring(at_position + 1));
}</FONT>
</FONT></FONT>
b.t.w., I don't prefer this naming convention but for recognition I didn't change them.
Gr,
Cybenny
Admin
Here's another e-mail validator I found in a webpage. Strangely enough, it doesn't even get called (alone with several dozen verification functions on that page).
function isValidEmail(address) {
if (address != '' && address.search) {
if (address.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
else return false;
}
else return true;
}
Can you see the WTF?
Admin
WTF - would anyone care to explain why on earth such a complex regular expression is required?
Unless I'm very much mistaken then the something like following only lacks tests for:
Obviously I stand to be corrected.
Admin
Actually, my submission was Javascript, whereas yours appears to be C#. Apples and oranges and all that.
Admin
Admin
I dont program in VB so I might be wrong, but doesn't the compiler infer the types? Or do you loose type-safety when not specifying types ?
Admin
Well, in Haskell this is the preferred way or formatting your code:
fac n = if n == 0 then 1 else n * fac (n-1)
Or perhaps:
fac 1 = 1
fac n = n * fac (n-1)
For simple functions like factorial I would actually prefer to keep it small.
So when I see
int Fact(int a) { if (a==0) return 1; else return a*Fact(a-1); }
I dont consider to be a big WTF as you call it.
Well I usually use parser combinators rather than regExpr because they integrate better within the language while being equally expressive. Esspecially in languages that allow you to define your own operators this can be a very clean and maintainable solution that skills well.
Making it so that it fixes the email-addres for example, would just be a little change, because your already operating in your normal environment. I tend to resist the urge to built javascript/html/parsers/sql straight from strings. Make or find a library that embeds it in the environment in a more natural way, catching possible construction errors. This pays off more in a statically typed environment off course.
Admin
Not exactly, and certainly not in the sense that a language like Haskell does. In VB 6, if you don't declare a variable's type, it is automatically assumed to be of type Variant, which is a polymorphic reference type - roughly equivalent to class Object in Java or Smalltalk, or void pointer in C. Every Variant has added metadata describing the type of the variable it references, which get set whenever the value is assigned. Furthermore, whenever any operator or function is applied to a Variant, the runtime library attempts to coerce the value to a type appropriate to the operation. While Variants are useful in a number of ways, they have considerable overhead when used for simple scalar types, and can lead to type conflicts if it can't find a way to coerce the value suitably.
Most VB shops will prevent implicit declarations such as these by requiring all source files to include the 'Option Explicit' pragma. Furthermore, VB.Net closes this loophole by forbidding undeclared types entirely - but then, as others have pointed out, VB.Net is a very different language from VB 6.
Admin
It would reject a perfectly valid bang-path
Admin
Many sites don't accept my perfectly valid (RFC822) email address: $^!#^$!^#$!^#$^!$#!^$^!#$^!#$^$#^!$#^!#$^$^!^$#^!$^#!^$#^!$#^!#$^!$#^!#$^#$^!$#^!$#$^$$^!#$^^!^!^#^#!^^#^$$^$#^^#^$^#^!#^$#^!$^@something-obscure.siliconcluster.net
And those same sites will no doubt accept: [email protected]
Email validation via anything other than confirmation emails does not work.