Jump to content

What does this regular expression do?


azhao

Recommended Posts

Hi all,

 

We had a developer who left our company a while ago. The following is a simplified Javascript snippet he wrote:

       

var reg_exp = /^[\000-\177]*$/;

if(reg_exp.test(document.getElementById('some_field').value == false) {

alert('Invalid format');

}

 

The purpose of the code is to validate Amazon product's description which the spec says "Type 1 High ASCII characters (® , ©, tm , etc.) or other special characters are not allowed" I assume jQuery is used here. What does that regular express match? What exactly are "Type 1 High ASCII characters? I did some researches on ASCII characters but couldn't find a definitive answer.

 

Please advise.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/156828-what-does-this-regular-expression-do/
Share on other sites

Well if ASCII, then they're in Octal format. It's just pretty much a whole array of keys that someone can type into a form. I don't see the point of it because the Regex test would almost always be true.

 

Also, your test method is missing a parenthesis.

 

if(reg_exp.test(document.getElementById('some_field').value) == false) {

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.