tba
tba

Reputation: 157

Regex for reverse DNS entry

I am trying to validate text field if it matches this kind of pattern for reverse DNS purpose

I tried ^\d+[^.*]|\.\d+|-in.addr.arpa.$

93    
93.12   
93.32.12 
93.32.12.10-in.addr.arpa.  
www.domain.com   
www  
domain..983   

but it matches the last one which is wrong it should match only the first 4 examples

Here is my rule

function check_record_NPTR(field){
    var regex = /^\d+[^.*]|\.\d+|-in.addr.arpa.$/;
    if(!regex.test(field.value)){
        highlight(field,true);
        return false;
    }
    else{
        highlight(field,false);
        return true;
    }

}

Upvotes: 0

Views: 3178

Answers (1)

Philipp Maurer
Philipp Maurer

Reputation: 2505

The regex you want to use instead is: ^(?:(?:\d+\.)*\d+(?:-in\.addr\.arpa\.)?)$

It will select each entry that starts with a number or a list of numbers seperated by dots, that optionally ends on the string -in.addr.arpa.

A good source to learn regex by experimenting is regexr.com in my experience.

To make that sufficient for a reverse DNS purpose you should read into how to limit the quantity of numbers in each number and add it to the regex. There is a ton of documentation about this.

Upvotes: 1

Related Questions