数字和' - '(Dash)字符的正则表达式

时间:2016-03-03 06:52:48

标签: asp.net regex

我想在asp.net中创建一个正则表达式,它允许使用以下格式的数值

12-1234-5678-0000-1

请帮忙。谢谢!

2 个答案:

答案 0 :(得分:2)

以下正则表达式将满足您的要求:

(function () {
  'use strict';

  angular
    .module('app.calc', [])
    .config(config);

  /** @ngInject */
  function config() {
  }
})();

Demo

describe('CalcController', function() {
  beforeEach(module('fuse'));
  beforeEach(module('app.calc'));

  var $controller;

  beforeEach(inject(function(_$controller_){
    $controller = _$controller_;
  }));

  describe('$scope.grade', function() {
    it('sets the strength to "strong" if the password length is >8 chars', function() {
      var $scope = {};
      var controller = $controller('CalcController', { $scope: $scope });
      $scope.password = 'longerthaneightchars';
      $scope.grade();
      expect($scope.strength).toEqual('strong');
    });
  });

  describe('test', function() {
    it('should work', function() {
      expect(true).toBe(true);
    });
  });
});

答案 1 :(得分:0)

string ip = "12-1234-5678-0000-1"; Match m = Regex.Match(ip, @"^[\d]{2}\-[\d]{4}\-[\d]{4}\-[\d]{4}\-[\d]{1}$"); Console.WriteLine(m.Success);