Negative selection (NS) is one of the most discussed algorithms in artificial immune system (AIS). With its unique property for anomaly detection, it has attracted the attention of researchers in the past decades. However, the processes on how to generate representative detectors and how to define the matching rules remain to be challenges in many NS applications. These difficulties make NS suffer from high false-positive rates and computational complexities. On the other hand, the Mahalanobis distance (MD) is a popular distance metric used in distinguishing patterns of a certain group from those of another group. Compared with other multivariate measurement techniques, MD is superior in its ability to determine the similarity of a set of values from an unknown sample to a set of values measured from a collection of known samples. In this study, an MD-based NS called MDNS is proposed to improve the classification power for anomaly detection by providing the mechanism to judge the quality of detector cells as well as to be applied to define the matching rules and the threshold in a matching rule. Two real cases concerning medical diagnosis and quality inspection in highly reliable products are studied, and the results show that the performance of the NS can be significantly improved by using the proposed approach.