2011年10月11日

[Asp.net] - XML Element Valid

XML Element 可以自定義名稱很方便,不過還是有一些限制 以下是他的規則
XML elements must follow these naming rules:

1.Names can contain letters, numbers, and other characters
2.Names cannot start with a number or punctuation character
3.Names cannot start with the letters xml (or XML, or Xml, etc)
4.Names cannot contain spaces

若是透過TextBox這類的控制項輸入Element時,就要做驗證了!

驗證的話可以寫一段javascript在寫入資料前做驗證

不過Asp.net提供類似的功能RegularExpressionValidator

可以針對某個控制項去做驗證

範例:




ValidationExpression="^(?!XML)(\D[.\S]*)"
//這段是在做驗證用的

RegularExpression寫的不太好

網路上有更多精準的pattern可以去套用!



參考:
1.http://stackoverflow.com/questions/2519845/how-to-check-if-string-is-a-valid-xml-element-name
2.yilin 的程式日記

沒有留言:

張貼留言