Results 1 to 6 of 6

Thread: ASP.NET validation

  1. #1
    Fanatic Member
    Join Date
    Feb 06
    Posts
    592

    ASP.NET validation

    I want to validate the entry allowing only CSS code ... if javascript, iframe and other intances of such are found it should throw an exception.

    Meaning they should be able to enter only .Func{param: blah;} and comments /*comment*/

    Thank you so much

  2. #2
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,546

    Re: ASP.NET validation

    You want to validate using only CCS(that i actually have no idea what you are asking anyhow) but yet again you want to use .Func{param: blah;} that is javascript.Can you explain exactly what do you want because your question does not make sense.Thanks.
    Slow as hell.

  3. #3
    Fanatic Member
    Join Date
    Feb 06
    Posts
    592

    Re: ASP.NET validation

    I have a TextBox control where people type stuff. They type everything including javascript code, html code, css code etc. etc. then everything is saved into database.
    What i want is that i validate what they typed there (on the server or client side) and warn them if they have typed anything but CSS.
    For instance
    VB.NET Code:
    1. If TextBox1.Text.Contains("<script") Then Alert('Your should use this field for css only') Else SaveIntoDatabase(TextBox1.Text)

    But, do you know any easy way instead checking all those non-css stuff?
    Thank you

    P.S. consider it to be css editor but nothing fancy.
    Last edited by selanec; Jul 21st, 2012 at 12:55 PM.

  4. #4
    King of sapila
    Join Date
    Oct 06
    Location
    Greece
    Posts
    3,546

    Re: ASP.NET validation

    Sorry i don't know of a simple way.You either need to use a regex(if exists) with RegularExpressionValidator, or you will have to find a CSS parser to use or you will have to do it in code as you stated.If your goal is to use the CSS that is written then i would suggest to find a CSS parser-validator to see if CSS checks alright and save it to database.
    Do some googling.
    Slow as hell.

  5. #5
    Frenzied Member brin351's Avatar
    Join Date
    Mar 07
    Location
    Land Down Under
    Posts
    1,257

    Re: ASP.NET validation

    The best approach is to use regex and validate for allowed chars. So word and ccs chars are allowed anything that is not fails validation. This is easier than trying to find all possible chars that you don't allow.

    Do you know regular expressions? The same expression will work both client and server side.

    lastly you can htmlEncode the input and htmlDecode only allowed chars so if anything slipped through validation it will be encoded and be treated as text in the browser.

    I don't know anything out of the box that does all this so if you need a hand let us know.
    The problem with computers is their nature is pure logic. Just once I'd like my computer to do something deluded.

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,837

    Re: ASP.NET validation

    Hello,

    Knowing the syntax of a language means that you can apply a lexer and parser to a code snippet to identify a language, in your case CSS.

    I have never played with it, but a quick google turned up this:

    http://www.antlr.org/

    Which you seem to be able to configure to identify the language of your choice.

    Might be worth taking a look.

    I also turned up this:

    http://www.phpied.com/css-lexer/

    Hope that helps!

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •