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
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) {

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.